| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 10 matching lines...) Expand all Loading... | |
| 21 import java.io.BufferedOutputStream; | 21 import java.io.BufferedOutputStream; |
| 22 import java.io.BufferedReader; | 22 import java.io.BufferedReader; |
| 23 import java.io.DataInputStream; | 23 import java.io.DataInputStream; |
| 24 import java.io.DataOutputStream; | 24 import java.io.DataOutputStream; |
| 25 import java.io.File; | 25 import java.io.File; |
| 26 import java.io.FileInputStream; | 26 import java.io.FileInputStream; |
| 27 import java.io.FileOutputStream; | 27 import java.io.FileOutputStream; |
| 28 import java.io.IOException; | 28 import java.io.IOException; |
| 29 import java.io.StringReader; | 29 import java.io.StringReader; |
| 30 import java.net.URL; | 30 import java.net.URL; |
| 31 import java.nio.charset.StandardCharsets; | |
| 31 import java.security.MessageDigest; | 32 import java.security.MessageDigest; |
| 32 import java.security.NoSuchAlgorithmException; | 33 import java.security.NoSuchAlgorithmException; |
| 33 import java.util.ArrayList; | 34 import java.util.ArrayList; |
| 34 import java.util.Collection; | 35 import java.util.Collection; |
| 35 import java.util.Collections; | 36 import java.util.Collections; |
| 36 import java.util.HashMap; | 37 import java.util.HashMap; |
| 37 import java.util.HashSet; | 38 import java.util.HashSet; |
| 38 import java.util.List; | 39 import java.util.List; |
| 39 import java.util.Locale; | 40 import java.util.Locale; |
| 40 import java.util.Map; | 41 import java.util.Map; |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 if (this.filters == null) | 430 if (this.filters == null) |
| 430 { | 431 { |
| 431 filtersOut.writeInt(0); | 432 filtersOut.writeInt(0); |
| 432 } | 433 } |
| 433 else | 434 else |
| 434 { | 435 { |
| 435 filtersOut.writeInt(this.filters.size()); | 436 filtersOut.writeInt(this.filters.size()); |
| 436 filtersOut.writeUTF(createFilterHash(new ArrayList<String>(this.filters) )); | 437 filtersOut.writeUTF(createFilterHash(new ArrayList<String>(this.filters) )); |
| 437 for (final String s : this.filters) | 438 for (final String s : this.filters) |
| 438 { | 439 { |
| 439 filtersOut.writeUTF(s); | 440 final byte[] b = s.getBytes(StandardCharsets.UTF_8); |
|
anton
2017/01/23 06:49:40
StandardCharsets is available starting Java 7. If
diegocarloslima
2017/01/30 17:14:30
For instance, I'll use Charset.forName("UTF-8"). T
| |
| 441 filtersOut.writeInt(b.length); | |
| 442 filtersOut.write(b); | |
| 440 } | 443 } |
| 441 } | 444 } |
| 442 } | 445 } |
| 443 finally | 446 finally |
| 444 { | 447 { |
| 445 filtersOut.close(); | 448 filtersOut.close(); |
| 446 } | 449 } |
| 447 } | 450 } |
| 448 | 451 |
| 449 public void serializeSubscription(final File metaFile, final File filtersFile) throws IOException | 452 public void serializeSubscription(final File metaFile, final File filtersFile) throws IOException |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 if (numFilters == 0) | 489 if (numFilters == 0) |
| 487 { | 490 { |
| 488 this.filters = null; | 491 this.filters = null; |
| 489 } | 492 } |
| 490 else | 493 else |
| 491 { | 494 { |
| 492 this.filters = new HashSet<String>(); | 495 this.filters = new HashSet<String>(); |
| 493 final String filtersHash = in.readUTF(); | 496 final String filtersHash = in.readUTF(); |
| 494 for (int i = 0; i < numFilters; i++) | 497 for (int i = 0; i < numFilters; i++) |
| 495 { | 498 { |
| 496 this.filters.add(in.readUTF()); | 499 final int length = in.readInt(); |
| 500 final byte[] b = new byte[length]; | |
| 501 in.readFully(b); | |
| 502 this.filters.add(new String(b, StandardCharsets.UTF_8)); | |
| 497 } | 503 } |
| 498 this.filtersValid = createFilterHash(new ArrayList<String>(this.filters) ).equals( | 504 this.filtersValid = createFilterHash(new ArrayList<String>(this.filters) ).equals( |
| 499 filtersHash); | 505 filtersHash); |
| 500 Log.d(TAG, "Filters valid: " + this.filtersValid); | 506 Log.d(TAG, "Filters valid: " + this.filtersValid); |
| 501 } | 507 } |
| 502 } | 508 } |
| 503 finally | 509 finally |
| 504 { | 510 { |
| 505 in.close(); | 511 in.close(); |
| 506 } | 512 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 this.serializeMetaData(metaFile); | 636 this.serializeMetaData(metaFile); |
| 631 if (filtersChanged) | 637 if (filtersChanged) |
| 632 { | 638 { |
| 633 this.serializeFilters(filtersFile); | 639 this.serializeFilters(filtersFile); |
| 634 this.clearFilters(); | 640 this.clearFilters(); |
| 635 } | 641 } |
| 636 | 642 |
| 637 return filtersChanged; | 643 return filtersChanged; |
| 638 } | 644 } |
| 639 } | 645 } |
| OLD | NEW |