JavaDigestValue implements DigestValue, Serializable { public static Set<JavaDigestValue> createDigestSet( Set<DigestAlgorithm> algorithms, InputStream is) throws NoSuchAlgorithmException, IOException { InputStream lastStream = is; Map<DigestAlgorithm, MessageDigest> digests = new HashMap<DigestAlgorithm, MessageDigest>(); for (DigestAlgorithm algorithm : algorithms) { MessageDigest digest = MessageDigest.getInstance(algorithm .getJavaName()); DigestInputStream dis = new DigestInputStream(lastStream, digest); digests.put(algorithm, digest); lastStream = dis; } BufferedInputStream bis = new BufferedInputStream(lastStream); byte[] buff = new byte[BUFFER_SIZE]; while ((bis.read(buff, 0, BUFFER_SIZE)) != -1) { } bis.close(); Set<JavaDigestValue> results = new HashSet<JavaDigestValue>(); for (DigestAlgorithm algorithm : digests.keySet()) { results.add(new JavaDigestValue(algorithm, digests.get(algorithm) .digest())); } return results; } JavaDigestValue();   JavaDigestValue(DigestAlgorithm algorithm, String hexDigest);   JavaDigestValue(DigestAlgorithm algorithm, byte[] digest); @Override URI getAlgorithmId(); @Override String getHexDigest(); @Override byte[] getDigest(); String toXml(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static JavaDigestValue getInstance(String xml); static JavaDigestValue getInstance(DigestAlgorithm algorithm,
			byte[] digest); static JavaDigestValue getInstance(DigestAlgorithm algorithm,
			String hexDigest); static JavaDigestValue getInstance(DigestAlgorithm algorithm,
			InputStream byteStream); static JavaDigestValue getInstance(DigestAlgorithm algorithm,
			File file); static Set<JavaDigestValue> createDigestSet(
			Set<DigestAlgorithm> algorithms, InputStream is);  }
@Test public void testCreateDigestSet() throws URISyntaxException, NoSuchAlgorithmException, FileNotFoundException, IOException { Set<DigestAlgorithm> algs = new HashSet<DigestAlgorithm>(); algs.add(DigestAlgorithm.MD5); algs.add(DigestAlgorithm.SHA); algs.add(DigestAlgorithm.SHA256); algs.add(DigestAlgorithm.SHA384); algs.add(DigestAlgorithm.SHA512); for (File file : AllCoreTest .getFilesFromResourceDir(AllCoreTest.TEST_DATA_ROOT)) { Set<JavaDigestValue> values = JavaDigestValue.createDigestSet(algs, new FileInputStream(file)); for (JavaDigestValue value : values) { switch (value.algorithm) { case MD5: assertArrayEquals("Digest byte arrays should be equal", DigestUtils.md5(new FileInputStream(file)), value.getDigest()); break; case SHA: assertArrayEquals("Digest byte arrays should be equal", DigestUtils.sha(new FileInputStream(file)), value.getDigest()); break; case SHA256: assertArrayEquals("Digest byte arrays should be equal", DigestUtils.sha256(new FileInputStream(file)), value.getDigest()); break; case SHA384: assertArrayEquals("Digest byte arrays should be equal", DigestUtils.sha384(new FileInputStream(file)), value.getDigest()); break; case SHA512: assertArrayEquals("Digest byte arrays should be equal", DigestUtils.sha512(new FileInputStream(file)), value.getDigest()); } } } }