IoUtil.write(hashingStream, new BufferedOutputStream(new FileOutputStream(tmpFile)), AbstractBinaryStore.MEDIUM_BUFFER_SIZE); byte[] sha1 = hashingStream.getHash(); BinaryKey key = new BinaryKey(sha1);
IoUtil.write(hashingStream, new BufferedOutputStream(new FileOutputStream(tmpFile)), AbstractBinaryStore.MEDIUM_BUFFER_SIZE); byte[] sha1 = hashingStream.getHash(); BinaryKey key = new BinaryKey(sha1);
protected void assertSecureHashStreamWorks( Algorithm algorithm, String resourceName ) throws IOException, NoSuchAlgorithmException { // Find the content of the file ... InputStream stream = getClass().getResourceAsStream(resourceName); assertThat(stream, is(notNullValue())); byte[] bytesThruStream = IoUtil.readBytes(stream); // Find the secure hash of the file ... stream = getClass().getResourceAsStream(resourceName); assertThat(stream, is(notNullValue())); byte[] hashThruStream = null; try { hashThruStream = SecureHash.getHash(algorithm, stream); } finally { stream.close(); } // Now try reading the stream using a hash stream ... stream = getClass().getResourceAsStream(resourceName); assertThat(stream, is(notNullValue())); HashingInputStream hashingStream = SecureHash.createHashingStream(algorithm, stream); byte[] bytesThruHashingStream = IoUtil.readBytes(hashingStream); // closes stream byte[] hashThruHashingStream = hashingStream.getHash(); // The content should be the same .. assertThat(bytesThruHashingStream, is(bytesThruStream)); // The hash should also be the same ... assertThat(hashThruHashingStream, is(hashThruStream)); // System.out.println(algorithm.digestName() + "---> " + hashingStream.getHashAsHexString() + " of " + resourceName); }