MetricsInputStream extends FilterInputStream { public String getMessageDigest() { return HEX.encode(messageDigest.digest()); } MetricsInputStream(final InputStream input); private  MetricsInputStream(final CountingInputStream countingStream, final MessageDigest messageDigest); String getMessageDigest(); long getSize(); StreamMetrics getMetrics();  }
@Test public void testHashesDiffer() throws Exception { final String hash1 = measure("ABC".getBytes("UTF-8")).getMessageDigest(); final String hash2 = measure(new byte[10000]).getMessageDigest(); assertThat(hash1, not(equalTo(hash2))); }
@Test public void referenceHashMatches() throws Exception { final MetricsInputStream measure = measure( getClass().getResourceAsStream("sha1_is_2589766c6dac3402cab552602d457e7e8af12efd.bytes")); assertThat(measure.getMessageDigest(), is(equalTo("2589766c6dac3402cab552602d457e7e8af12efd"))); }