Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java |
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..88334d1612d3d48407f97bc2254f78d05a4570ac |
--- /dev/null |
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java |
@@ -0,0 +1,90 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-2016 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+package org.adblockplus.libadblockplus; |
+ |
+import org.adblockplus.android.Utils; |
+ |
+import android.util.Log; |
+ |
+import java.io.File; |
+import java.util.UUID; |
+ |
+public class FileSystemUtils |
+{ |
+ private static final String TAG = Utils.getTag(FileSystemUtils.class); |
+ |
+ // File.createTempFile() creates a file instead of just generating unique file name |
+ |
+ public static String generateUniqueFileName(String prefix, String suffix) |
+ { |
+ StringBuilder sb = new StringBuilder(); |
+ if (prefix != null) |
+ { |
+ sb.append(prefix); |
+ } |
+ sb.append(UUID.randomUUID()); |
+ if (suffix != null) |
+ { |
+ sb.append(suffix); |
+ } |
+ return sb.toString(); |
+ } |
+ |
+ public static File generateUniqueFile(String prefix, String suffix, File parent) |
+ { |
+ return new File(parent, generateUniqueFileName(prefix, suffix)); |
+ } |
+ |
+ public static void delete(String filePath, boolean deleteSelf) |
Felix Dahlke
2017/05/09 08:06:45
I may have missed something, but it appears `delet
anton
2017/05/10 11:00:14
Done.
|
+ { |
+ delete(new File(filePath), deleteSelf); |
+ } |
+ |
+ public static void delete(File file, boolean deleteSelf) |
+ { |
+ if (file.isDirectory()) |
+ { |
+ deleteDirectory(file, deleteSelf); |
+ } |
+ else |
+ { |
+ deleteFile(file); |
+ } |
+ } |
+ |
+ public static void deleteDirectory(File directory, boolean deleteSelf) |
+ { |
+ File files[] = directory.listFiles(); |
+ for (File eachFile : files) |
+ { |
+ delete(eachFile, true); |
+ } |
+ |
+ if (deleteSelf) |
+ { |
+ Log.w(TAG, "Deleting directory " + directory.getAbsolutePath()); |
+ directory.delete(); |
+ } |
+ } |
+ |
+ public static void deleteFile(File file) |
+ { |
+ Log.w(TAG, "Deleting file " + file.getAbsolutePath()); |
+ file.delete(); |
+ } |
+} |