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..b92d693e7b8adfa5745f1fdfce75d5a3a568d8ef |
--- /dev/null |
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java |
@@ -0,0 +1,88 @@ |
+/* |
+ * 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 android.util.Log; |
+ |
+import java.io.File; |
+import java.util.UUID; |
+ |
+public class FileSystemUtils |
anton
2016/08/08 07:52:51
also renamed FileSystemHelper to FileSystemUtils t
|
+{ |
+ private static final String TAG = FileSystemUtils.class.getSimpleName(); |
diegocarloslima
2016/09/09 01:34:14
You might want to use Utils.getTag() to be consist
anton
2016/09/09 06:50:53
Acknowledged.
|
+ |
+ // File.createTempFile() creates a file instead of just generating unique file name |
+ |
+ public 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 File generateUniqueFileName(String prefix, String suffix, File parent) |
+ { |
+ return new File(parent, generateUniqueFileName(prefix, suffix)); |
+ } |
diegocarloslima
2016/09/09 01:34:14
I think that it would be more consistent if both o
anton
2016/09/09 06:50:53
Acknowledged.
|
+ |
+ public void delete(String filePath, boolean deleteSelf) |
+ { |
+ delete(new File(filePath), deleteSelf); |
+ } |
+ |
+ public void delete(File file, boolean deleteSelf) |
+ { |
+ if (file.isDirectory()) |
+ { |
+ deleteDirectory(file, deleteSelf); |
+ } |
+ else |
+ { |
+ deleteFile(file); |
+ } |
+ } |
+ |
+ public 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 void deleteFile(File file) |
+ { |
+ Log.w(TAG, "Deleting file " + file.getAbsolutePath()); |
+ file.delete(); |
+ } |
+} |
diegocarloslima
2016/09/09 01:34:14
Since none of these methods retains any state for
anton
2016/09/09 06:50:53
Acknowledged.
|