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

Delta Between Two Patch Sets: libadblockplus-android/src/org/adblockplus/libadblockplus/FileSystemUtils.java

Issue 29347315: Issue 4231 - Fix unstable FilterEngineTest.testSetRemoveFilterChangeCallback (Closed)
Left Patch Set: patchset 2 + patchset 3 + applied Eyeo's codestyle Created Aug. 8, 2016, 8:09 a.m.
Right Patch Set: made helper methods static, fixed 'remove' for fs callback Created Dec. 13, 2016, 9:32 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 16 matching lines...) Expand all
27 27
28 public class FileSystemUtils 28 public class FileSystemUtils
29 { 29 {
30 /** 30 /**
31 * Read all the file data to string 31 * Read all the file data to string
32 * 32 *
33 * @param file path to read data 33 * @param file path to read data
34 * @return file data 34 * @return file data
35 * @throws java.io.FileNotFoundException 35 * @throws java.io.FileNotFoundException
36 */ 36 */
37 public String readFile(File file) throws FileNotFoundException 37 public static String readFile(File file) throws FileNotFoundException
38 { 38 {
39 Scanner scanner = null; 39 Scanner scanner = null;
40 try 40 try
41 { 41 {
42 scanner = new Scanner(file); 42 scanner = new Scanner(file);
43 return scanner.useDelimiter("\\A").next(); 43 return scanner.useDelimiter("\\A").next();
44 } 44 }
45 catch (NoSuchElementException e) 45 catch (NoSuchElementException e)
46 { 46 {
47 return ""; 47 return "";
48 } 48 }
49 finally 49 finally
50 { 50 {
51 if (scanner != null) 51 if (scanner != null)
52 { 52 {
53 scanner.close(); 53 scanner.close();
54 } 54 }
55 } 55 }
56 } 56 }
57 57
58 /** 58 /**
59 * Write data to file (with rewriting) 59 * Write data to file (with rewriting)
60 * 60 *
61 * @param file file 61 * @param file file
62 * @param data file data 62 * @param data file data
63 */ 63 */
64 public void writeFile(File file, String data) throws IOException 64 public static void writeFile(File file, String data) throws IOException
65 { 65 {
66 FileOutputStream fos = null; 66 FileOutputStream fos = null;
67 try 67 try
68 { 68 {
69 fos = new FileOutputStream(file); 69 fos = new FileOutputStream(file);
70 if (data != null) 70 if (data != null)
71 { 71 {
72 fos.write(data.getBytes()); 72 fos.write(data.getBytes());
73 } 73 }
74 } 74 }
75 finally 75 finally
76 { 76 {
77 if (fos != null) 77 if (fos != null)
78 { 78 {
79 try 79 try
80 { 80 {
81 fos.close(); 81 fos.close();
diegocarloslima 2017/04/27 12:22:40 Are we using Java 7 already in libadblockplus-andr
anton 2017/04/28 08:25:45 it's not clear but seems that "not yet". For now i
82 } 82 }
83 catch (IOException e) 83 catch (IOException e)
84 { 84 {
85 // ignored 85 // ignored
86 } 86 }
87 } 87 }
88 } 88 }
89 } 89 }
90 90
91 /** 91 /**
92 * Generate unique filename 92 * Generate unique filename
93 * 93 *
94 * @param prefix prefix 94 * @param prefix prefix
95 * @param suffix suffix 95 * @param suffix suffix
96 * @return generated unique filename 96 * @return generated unique filename
97 */ 97 */
98 public String generateUniqueFileName(String prefix, String suffix) 98 public static String generateUniqueFileName(String prefix, String suffix)
99 { 99 {
100 StringBuilder sb = new StringBuilder(); 100 StringBuilder sb = new StringBuilder();
101 if (prefix != null) 101 if (prefix != null)
102 { 102 {
103 sb.append(prefix); 103 sb.append(prefix);
104 } 104 }
105 105
106 sb.append(UUID.randomUUID().toString()); 106 sb.append(UUID.randomUUID().toString());
107 107
108 if (suffix != null) 108 if (suffix != null)
109 { 109 {
110 sb.append(suffix); 110 sb.append(suffix);
111 } 111 }
112 112
113 return sb.toString(); 113 return sb.toString();
114 } 114 }
115 } 115 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld