Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java

Issue 29347192: Issue 4181 - Fix FilterEngineTest tests (Closed)
Patch Set: marked method as static Created Dec. 2, 2016, 6:14 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(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 org.adblockplus.android.Utils;
21
22 import android.util.Log;
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, boolean deleteSelf)
Felix Dahlke 2017/05/09 08:06:45 I may have missed something, but it appears `delet
anton 2017/05/10 11:00:14 Done.
54 {
55 delete(new File(filePath), deleteSelf);
56 }
57
58 public static void delete(File file, boolean deleteSelf)
59 {
60 if (file.isDirectory())
61 {
62 deleteDirectory(file, deleteSelf);
63 }
64 else
65 {
66 deleteFile(file);
67 }
68 }
69
70 public static void deleteDirectory(File directory, boolean deleteSelf)
71 {
72 File files[] = directory.listFiles();
73 for (File eachFile : files)
74 {
75 delete(eachFile, true);
76 }
77
78 if (deleteSelf)
79 {
80 Log.w(TAG, "Deleting directory " + directory.getAbsolutePath());
81 directory.delete();
82 }
83 }
84
85 public static void deleteFile(File file)
86 {
87 Log.w(TAG, "Deleting file " + file.getAbsolutePath());
88 file.delete();
89 }
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld