| 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..735bcf58140b9d02eb406163603c09385d101120 |
| --- /dev/null |
| +++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java |
| @@ -0,0 +1,87 @@ |
| +/* |
| + * This file is part of Adblock Plus <https://adblockplus.org/>, |
| + * Copyright (C) 2006-2017 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 org.adblockplus.libadblockplus.android.Utils; |
| + |
| +import java.io.File; |
| +import java.util.UUID; |
| + |
| +public class FileSystemUtils |
|
anton
2017/05/10 11:02:33
BTW we could use Apache file utils in the tests at
|
| +{ |
| + 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) |
| + { |
| + delete(new File(filePath)); |
| + } |
| + |
| + public static void delete(File file) |
| + { |
| + if (file.isDirectory()) |
| + { |
| + deleteDirectory(file); |
| + } |
| + else |
| + { |
| + deleteFile(file); |
| + } |
| + } |
| + |
| + public static void deleteDirectory(File directory) |
| + { |
| + File files[] = directory.listFiles(); |
| + for (File eachFile : files) |
| + { |
| + delete(eachFile); |
| + } |
| + |
| + Log.w(TAG, "Deleting directory " + directory.getAbsolutePath()); |
| + directory.delete(); |
| + } |
| + |
| + public static void deleteFile(File file) |
| + { |
| + Log.w(TAG, "Deleting file " + file.getAbsolutePath()); |
| + file.delete(); |
| + } |
| +} |