diff --git a/briar-android/src/org/briarproject/android/util/AndroidUtils.java b/briar-android/src/org/briarproject/android/util/AndroidUtils.java index fb47a7abe9e9603e4e1dfcdd97ee538b30f1bc6e..610e480e51bb684d2a03cef9f590dc92bb484436 100644 --- a/briar-android/src/org/briarproject/android/util/AndroidUtils.java +++ b/briar-android/src/org/briarproject/android/util/AndroidUtils.java @@ -9,7 +9,7 @@ import android.support.design.widget.TextInputLayout; import android.text.format.DateUtils; import org.briarproject.R; -import org.briarproject.util.FileUtils; +import org.briarproject.util.IoUtils; import org.briarproject.util.StringUtils; import java.io.File; @@ -89,7 +89,7 @@ public class AndroidUtils { if (children != null) { for (File child : children) { if (!child.getName().equals("lib")) - FileUtils.deleteFileOrDir(child); + IoUtils.deleteFileOrDir(child); } } } diff --git a/briar-core/src/org/briarproject/util/FileUtils.java b/briar-core/src/org/briarproject/util/FileUtils.java deleted file mode 100644 index 6bd5886f6b4c1635d15bb6a9f64dbaafd3e5f6f7..0000000000000000000000000000000000000000 --- a/briar-core/src/org/briarproject/util/FileUtils.java +++ /dev/null @@ -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(); - } - } -} diff --git a/briar-core/src/org/briarproject/util/IoUtils.java b/briar-core/src/org/briarproject/util/IoUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..c149b024e16017e51d91f449e0613f1f57b34815 --- /dev/null +++ b/briar-core/src/org/briarproject/util/IoUtils.java @@ -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(); + } + } + +} diff --git a/briar-tests/src/org/briarproject/TestUtils.java b/briar-tests/src/org/briarproject/TestUtils.java index 023b800d9e55f2766d3a0f30488f4fbe6bce8caa..95a6d1ac4cf1ef42e186e0c8dd5603e3f45acb92 100644 --- a/briar-tests/src/org/briarproject/TestUtils.java +++ b/briar-tests/src/org/briarproject/TestUtils.java @@ -2,7 +2,7 @@ package org.briarproject; import org.briarproject.api.UniqueId; import org.briarproject.api.crypto.SecretKey; -import org.briarproject.util.FileUtils; +import org.briarproject.util.IoUtils; import java.io.File; import java.util.Random; @@ -20,7 +20,7 @@ public class TestUtils { } public static void deleteTestDirectory(File testDir) { - FileUtils.deleteFileOrDir(testDir); + IoUtils.deleteFileOrDir(testDir); testDir.getParentFile().delete(); // Delete if empty }