use of org.commonjava.maven.galley.io.checksum.Md5GeneratorFactory.Md5Generator in project galley by Commonjava.
the class Md5GeneratorFactoryTest method verifyWithMessageDigest.
@Test
public void verifyWithMessageDigest() throws Exception {
final byte[] data = "this is a test".getBytes();
final Transfer txfr = fixture.getCache().getTransfer(new ConcreteResource(new SimpleLocation("test:uri"), "my-path.txt"));
final Md5GeneratorFactory factory = new Md5GeneratorFactory();
final Md5Generator generator = factory.newGenerator(txfr, true);
generator.update(data);
generator.write();
final MessageDigest md = MessageDigest.getInstance("MD5");
md.update(data);
final byte[] digest = md.digest();
final String digestHex = Hex.encodeHexString(digest);
final Transfer md5Txfr = txfr.getSiblingMeta(".md5");
InputStream in = null;
String resultHex = null;
try {
in = md5Txfr.openInputStream();
resultHex = IOUtils.toString(in);
} finally {
IOUtils.closeQuietly(in);
}
assertThat(resultHex, equalTo(digestHex));
}
Aggregations