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

Delta Between Two Patch Sets: src/org/adblockplus/sbrowser/contentblocker/engine/Subscriptions.java

Issue 29372653: Issue 4813 - UTFDataFormatException while serializing filter (Closed)
Left Patch Set: Created Jan. 18, 2017, 1:36 p.m.
Right Patch Set: Including UTF-8 constant and adding migration/file corruption recovery logic Created March 9, 2017, 7:38 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/org/adblockplus/sbrowser/contentblocker/engine/Subscription.java ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 * @throws IOException 164 * @throws IOException
165 */ 165 */
166 private void writeFile(final File output) throws IOException 166 private void writeFile(final File output) throws IOException
167 { 167 {
168 final HashSet<String> filters = new HashSet<String>(); 168 final HashSet<String> filters = new HashSet<String>();
169 for (final Subscription s : this.subscriptions.values()) 169 for (final Subscription s : this.subscriptions.values())
170 { 170 {
171 if (s.isEnabled()) 171 if (s.isEnabled())
172 { 172 {
173 Log.d(TAG, "Adding filters for '" + s.getId() + "'"); 173 Log.d(TAG, "Adding filters for '" + s.getId() + "'");
174 s.deserializeFilters(this.getFiltersFile(s));
175 s.copyFilters(filters);
174 s.clearFilters(); 176 s.clearFilters();
175 s.deserializeFilters(this.getFiltersFile(s)); 177 }
176 s.getFilters(filters); 178 if ((!s.isMetaDataValid() || !s.isFiltersValid()) && s.getURL() != null)
177 s.clearFilters(); 179 {
180 this.engine.enqueueDownload(s, true);
178 } 181 }
179 } 182 }
180 183
181 final BufferedWriter w = new BufferedWriter( 184 final BufferedWriter w = new BufferedWriter(
182 new OutputStreamWriter(new FileOutputStream(output), "UTF-8")); 185 new OutputStreamWriter(new FileOutputStream(output), Engine.CHARSET_UTF_ 8));
183 try 186 try
184 { 187 {
185 Log.d(TAG, "Writing " + filters.size() + " filters"); 188 Log.d(TAG, "Writing " + filters.size() + " filters");
186 Engine.writeFilterHeaders(w); 189 Engine.writeFilterHeaders(w);
187 for (final String filter : filters) 190 for (final String filter : filters)
188 { 191 {
189 w.write(filter); 192 w.write(filter);
190 w.write('\n'); 193 w.write('\n');
191 } 194 }
192 } 195 }
193 finally 196 finally
194 { 197 {
195 w.close(); 198 w.close();
196 } 199 }
197 } 200 }
198 201
199 public Subscription add(final Subscription sub) 202 public Subscription add(final Subscription sub)
200 { 203 {
201 final String id = sub.getId(); 204 final String id = sub.getId();
202 if (!this.subscriptions.containsKey(id)) 205 if (!this.subscriptions.containsKey(id))
203 { 206 {
204 this.subscriptions.put(id, sub); 207 this.subscriptions.put(id, sub);
205 return sub; 208 return sub;
206 } 209 }
207 return this.subscriptions.get(id); 210 return this.subscriptions.get(id);
208 } 211 }
209 212
210 public static Subscriptions initialize(final Engine engine, final File appFold er, 213 public static Subscriptions initialize(final Engine engine, final File appFold er,
211 final File cacheFolder) 214 final File cacheFolder)
212 throws IOException
213 { 215 {
214 final Subscriptions subs = new Subscriptions(engine, appFolder, cacheFolder) ; 216 final Subscriptions subs = new Subscriptions(engine, appFolder, cacheFolder) ;
215 217
216 subs.subscriptionFolder.mkdirs(); 218 subs.subscriptionFolder.mkdirs();
217 subs.cacheFolder.mkdirs(); 219 subs.cacheFolder.mkdirs();
218 220
219 final File[] files = subs.subscriptionFolder.listFiles(); 221 final File[] files = subs.subscriptionFolder.listFiles();
220 for (File f : files) 222 for (File f : files)
221 { 223 {
222 if (f.getName().endsWith(".sub")) 224 if (f.getName().endsWith(".sub"))
223 { 225 {
224 final File metaFile = new File(f.getAbsolutePath() + ".meta"); 226 final File metaFile = new File(f.getAbsolutePath() + ".meta");
225 if (metaFile.exists()) 227 if (metaFile.exists())
226 { 228 {
227 final Subscription sub = Subscription.deserializeSubscription(metaFile ); 229 final Subscription sub = Subscription.deserializeSubscription(metaFile );
228 subs.subscriptions.put(sub.getId(), sub); 230 if (sub != null)
231 {
232 subs.subscriptions.put(sub.getId(), sub);
233 }
229 } 234 }
230 } 235 }
231 } 236 }
232 237
233 subs.createUserSubscriptions(); 238 subs.createUserSubscriptions();
234 239
235 return subs; 240 return subs;
236 } 241 }
237 242
238 /** 243 /**
(...skipping 30 matching lines...) Expand all
269 if (sub != null) 274 if (sub != null)
270 { 275 {
271 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub), 276 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub),
272 this.getFiltersFile(sub))) 277 this.getFiltersFile(sub)))
273 { 278 {
274 this.engine.requestUpdateBroadcast(); 279 this.engine.requestUpdateBroadcast();
275 } 280 }
276 } 281 }
277 } 282 }
278 } 283 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld