HyperLogLogCodec { public AdaptiveHyperLogLog decodeAdaptiveHyperLogLog(InputStream in) throws IOException { return decodeAdaptiveHyperLogLog(new DataInputStream(in)); }  void encodeHyperLogLog(HyperLogLog hyperLogLog, OutputStream out); void encodeHyperLogLog(HyperLogLog hyperLogLog, DataOutputStream out); void encodeAdaptiveHyperLogLog(AdaptiveHyperLogLog hyperLogLog, OutputStream out); void encodeAdaptiveHyperLogLog(AdaptiveHyperLogLog hyperLogLog, DataOutputStream out); void encodeBuckets(DataOutputStream out, int[] buckets, float estimate); HyperLogLog decodeHyperLogLog(InputStream in); HyperLogLog decodeHyperLogLog(DataInputStream in); AdaptiveHyperLogLog decodeAdaptiveHyperLogLog(InputStream in); AdaptiveHyperLogLog decodeAdaptiveHyperLogLog(DataInputStream in); static SortedStaticModel createHyperLogLogSymbolModel(
      long estimate, int bucketCount, byte maxValue); static double[] hyperLogLogProbabilities(
      long cardinality, int bucketCount, byte maxValue); static double probabilityRegisterLessThan(long cardinality, int bucketCount, int value);  }
@Test public void testDeserializationBackwardsCompatibility() throws Exception { HyperLogLogCodec codec = new HyperLogLogCodec(); for (int cardinality = 10; cardinality <= 100000; cardinality *= 10) { for (int bucketCount = 1024; bucketCount <= 4096; bucketCount <<= 1) { String fileBaseName = String.format("serialization/HyperLogLog-%d-%d", bucketCount, cardinality); AdaptiveHyperLogLog expected; InputStream in = getClass().getClassLoader().getResourceAsStream(fileBaseName + ".raw"); try { int[] buckets = new int[bucketCount]; for (int i = 0; i < bucketCount; i++) { buckets[i] = in.read(); } expected = new AdaptiveHyperLogLog(buckets); } finally { Closeables.close(in, true); } AdaptiveHyperLogLog actual; in = getClass().getClassLoader().getResourceAsStream(fileBaseName + ".ser"); try { actual = codec.decodeAdaptiveHyperLogLog(in); } finally { Closeables.close(in, true); } assertEquals(actual.buckets(), expected.buckets()); assertEquals(actual.estimate(), expected.estimate()); } } }