| 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..1c59ebc28ad4016952cf9459ff1a35f88d51171a |
| --- /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 void delete(String filePath, boolean deleteSelf) |
|
diegocarloslima
2016/11/03 14:06:02
This method is missing the static modifier
anton
2016/12/02 06:15:03
Acknowledged.
|
| + { |
| + 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(); |
| + } |
| +} |