Example #1
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);
    }
  }
  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);
    }
  }