mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Renamed FIleUtils to IoUtils, added copy() method.
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
package org.briarproject.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static void deleteFileOrDir(File f) {
|
||||
if (f.isFile()) {
|
||||
f.delete();
|
||||
} else if (f.isDirectory()) {
|
||||
File[] children = f.listFiles();
|
||||
if (children != null)
|
||||
for (File child : children) deleteFileOrDir(child);
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
40
briar-core/src/org/briarproject/util/IoUtils.java
Normal file
40
briar-core/src/org/briarproject/util/IoUtils.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package org.briarproject.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class IoUtils {
|
||||
|
||||
public static void deleteFileOrDir(File f) {
|
||||
if (f.isFile()) {
|
||||
f.delete();
|
||||
} else if (f.isDirectory()) {
|
||||
File[] children = f.listFiles();
|
||||
if (children != null)
|
||||
for (File child : children) deleteFileOrDir(child);
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static void copy(InputStream in, OutputStream out)
|
||||
throws IOException {
|
||||
byte[] buf = new byte[4096];
|
||||
try {
|
||||
try {
|
||||
while (true) {
|
||||
int read = in.read(buf);
|
||||
if (read == -1) break;
|
||||
out.write(buf, 0, read);
|
||||
}
|
||||
out.flush();
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user