Esempio n. 1
0
 public static NumberFilter deserializeFromFile(Context context) {
   try {
     FileInputStream fis = context.openFileInput(DIRECTORY_FILE);
     NumberFilterStorage storage = NumberFilterStorage.fromStream(fis);
     return new NumberFilter(
         new BloomFilter(Base64.decode(storage.getFilterData()), storage.getHashCount()));
   } catch (IOException ioe) {
     Log.w("NumberFilter", ioe);
     return new NumberFilter(null);
   }
 }
Esempio n. 2
0
  private byte[] getZID() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    if (preferences.contains("ZID")) {
      try {
        return Base64.decode(preferences.getString("ZID", null));
      } catch (IOException e) {
        return setZID();
      }
    } else {
      return setZID();
    }
  }
Esempio n. 3
0
  private byte[] setZID() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    try {
      byte[] zid = new byte[12];
      SecureRandom.getInstance("SHA1PRNG").nextBytes(zid);
      String encodedZid = Base64.encodeBytes(zid);

      preferences.edit().putString("ZID", encodedZid).commit();

      return zid;
    } catch (NoSuchAlgorithmException e) {
      throw new IllegalArgumentException(e);
    }
  }
Esempio n. 4
0
  public void serializeToFile(Context context) {
    if (this.bloomFilter == null) return;

    try {
      FileOutputStream fout = context.openFileOutput(DIRECTORY_FILE, 0);
      String numberFilter = Base64.encodeBytes(bloomFilter.getFilter());
      NumberFilterStorage storage =
          new NumberFilterStorage(numberFilter, bloomFilter.getHashCount());

      storage.serializeToStream(fout);
      fout.close();
    } catch (IOException ioe) {
      Log.w("NumberFilter", ioe);
    }
  }