Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2016 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 java.io.File; | |
23 import java.util.UUID; | |
24 | |
25 public class FileSystemUtils | |
anton
2016/08/08 07:52:51
also renamed FileSystemHelper to FileSystemUtils t
| |
26 { | |
27 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.
| |
28 | |
29 // File.createTempFile() creates a file instead of just generating unique file name | |
30 | |
31 public String generateUniqueFileName(String prefix, String suffix) | |
32 { | |
33 StringBuilder sb = new StringBuilder(); | |
34 if (prefix != null) | |
35 { | |
36 sb.append(prefix); | |
37 } | |
38 sb.append(UUID.randomUUID()); | |
39 if (suffix != null) | |
40 { | |
41 sb.append(suffix); | |
42 } | |
43 return sb.toString(); | |
44 } | |
45 | |
46 public File generateUniqueFileName(String prefix, String suffix, File parent) | |
47 { | |
48 return new File(parent, generateUniqueFileName(prefix, suffix)); | |
49 } | |
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.
| |
50 | |
51 public void delete(String filePath, boolean deleteSelf) | |
52 { | |
53 delete(new File(filePath), deleteSelf); | |
54 } | |
55 | |
56 public void delete(File file, boolean deleteSelf) | |
57 { | |
58 if (file.isDirectory()) | |
59 { | |
60 deleteDirectory(file, deleteSelf); | |
61 } | |
62 else | |
63 { | |
64 deleteFile(file); | |
65 } | |
66 } | |
67 | |
68 public void deleteDirectory(File directory, boolean deleteSelf) | |
69 { | |
70 File files[] = directory.listFiles(); | |
71 for (File eachFile : files) | |
72 { | |
73 delete(eachFile, true); | |
74 } | |
75 | |
76 if (deleteSelf) | |
77 { | |
78 Log.w(TAG, "Deleting directory " + directory.getAbsolutePath()); | |
79 directory.delete(); | |
80 } | |
81 } | |
82 | |
83 public void deleteFile(File file) | |
84 { | |
85 Log.w(TAG, "Deleting file " + file.getAbsolutePath()); | |
86 file.delete(); | |
87 } | |
88 } | |
diegocarloslima
2016/09/09 01:34:14
Since none of these methods retains any state for
anton
2016/09/09 06:50:53
Acknowledged.
| |
OLD | NEW |