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

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

Issue 29347192: Issue 4181 - Fix FilterEngineTest tests (Closed)
Patch Set: Created July 1, 2016, 1:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 android.util.Log;
21
22 import java.io.File;
23 import java.util.UUID;
24
25 public class FileSystemHelper
26 {
27 private static final String TAG = FileSystemHelper.class.getSimpleName();
28
29 // File.createTempFile() creates a file instead of just generating unique fi le name
30
31 public String generateUniqueFileName(String prefix, String suffix)
32 {
33 StringBuilder sb = new StringBuilder();
34 if (prefix != null)
35 sb.append(prefix);
36 sb.append(UUID.randomUUID());
37 if (suffix != null)
38 sb.append(suffix);
39 return sb.toString();
40 }
41
42 public File generateUniqueFileName(String prefix, String suffix, File parent )
43 {
44 return new File(parent, generateUniqueFileName(prefix, suffix));
45 }
46
47 public void delete(String filePath, boolean deleteSelf)
48 {
49 delete(new File(filePath), deleteSelf);
50 }
51
52 public void delete(File file, boolean deleteSelf)
53 {
54 if (file.isDirectory())
55 deleteDirectory(file, deleteSelf);
56 else
57 deleteFile(file);
58 }
59
60 public void deleteDirectory(File directory, boolean deleteSelf)
61 {
62 File files[] = directory.listFiles();
63 for (File eachFile : files)
64 delete(eachFile, true);
65
66 if (deleteSelf)
67 {
68 Log.w(TAG, "Deleting directory " + directory.getAbsolutePath());
69 directory.delete();
70 }
71 }
72
73 public void deleteFile(File file)
74 {
75 Log.w(TAG, "Deleting file " + file.getAbsolutePath());
76 file.delete();
77 }
78 }
OLDNEW
« no previous file with comments | « no previous file | libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld