OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH |
| 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 package org.adblockplus.libadblockplus; |
| 19 |
| 20 import android.util.Log; |
| 21 |
| 22 import org.adblockplus.libadblockplus.android.Utils; |
| 23 |
| 24 import java.io.File; |
| 25 import java.util.UUID; |
| 26 |
| 27 public class FileSystemUtils |
| 28 { |
| 29 private static final String TAG = Utils.getTag(FileSystemUtils.class); |
| 30 |
| 31 // File.createTempFile() creates a file instead of just generating unique file
name |
| 32 |
| 33 public static String generateUniqueFileName(String prefix, String suffix) |
| 34 { |
| 35 StringBuilder sb = new StringBuilder(); |
| 36 if (prefix != null) |
| 37 { |
| 38 sb.append(prefix); |
| 39 } |
| 40 sb.append(UUID.randomUUID()); |
| 41 if (suffix != null) |
| 42 { |
| 43 sb.append(suffix); |
| 44 } |
| 45 return sb.toString(); |
| 46 } |
| 47 |
| 48 public static File generateUniqueFile(String prefix, String suffix, File paren
t) |
| 49 { |
| 50 return new File(parent, generateUniqueFileName(prefix, suffix)); |
| 51 } |
| 52 |
| 53 public static void delete(String filePath) |
| 54 { |
| 55 delete(new File(filePath)); |
| 56 } |
| 57 |
| 58 public static void delete(File file) |
| 59 { |
| 60 if (file.isDirectory()) |
| 61 { |
| 62 deleteDirectory(file); |
| 63 } |
| 64 else |
| 65 { |
| 66 deleteFile(file); |
| 67 } |
| 68 } |
| 69 |
| 70 public static void deleteDirectory(File directory) |
| 71 { |
| 72 File files[] = directory.listFiles(); |
| 73 for (File eachFile : files) |
| 74 { |
| 75 delete(eachFile); |
| 76 } |
| 77 |
| 78 Log.w(TAG, "Deleting directory " + directory.getAbsolutePath()); |
| 79 directory.delete(); |
| 80 } |
| 81 |
| 82 public static void deleteFile(File file) |
| 83 { |
| 84 Log.w(TAG, "Deleting file " + file.getAbsolutePath()); |
| 85 file.delete(); |
| 86 } |
| 87 } |
OLD | NEW |