public void testHash_hashesCorrectly() throws Exception { byte[] buf = new byte[] {'y', 'a', 'm', 's'}; HashCode expectedHash = Hashing.md5().hashBytes(buf); HashingOutputStream out = new HashingOutputStream(Hashing.md5(), buffer); out.write(buf); assertEquals(expectedHash, out.hash()); }
public void testWrite_putByteArrayAtPos() throws Exception { byte[] buf = new byte[] {'y', 'a', 'm', 's'}; HashingOutputStream out = new HashingOutputStream(hashFunction, buffer); out.write(buf, 0, 3); verify(hashFunction).newHasher(); verify(hasher).putBytes(buf, 0, 3); verifyNoMoreInteractions(hashFunction, hasher); }
final HashingOutputStream hos = new HashingOutputStream(Hashing.md5(), cos); representation.writeTo(hos); hos.close(); hash.set(NFO.HASH_VALUE, hos.hash().toString()); metadata.set(NFO.HAS_HASH, hash); metadata.set(NFO.FILE_SIZE, cos.getCount());
DigestOutputStream md5DigestOutputStream = new DigestOutputStream( nullOutputStream, MessageDigest.getInstance("MD5")); HashingOutputStream crc32cHashingOutputStream = new HashingOutputStream(Hashing.crc32c(), md5DigestOutputStream); ObjectsDownloadExample.downloadToOutputStream(storage, settings.getBucket(), + (object.getMd5Hash().equals(calculatedMD5) ? "(MATCHES)" : "(MISMATCHES; data altered in transit)")); int calculatedCrc32c = crc32cHashingOutputStream.hash().asInt(); String calculatedEncodedCrc32c = BaseEncoding.base64().encode( Ints.toByteArray(calculatedCrc32c)); + crc32cHashingOutputStream.hash().asInt() + " " + (object.getCrc32c().equals(calculatedEncodedCrc32c) ? "(MATCHES)" : "(MISMATCHES; data altered in transit)"));
public void testChecksForNull() throws Exception { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicInstanceMethods( new HashingOutputStream(Hashing.md5(), new ByteArrayOutputStream())); tester.testAllPublicStaticMethods(HashingOutputStream.class); tester.testAllPublicConstructors(HashingOutputStream.class); } }
public void testWrite_putSingleByte() throws Exception { int b = 'q'; HashingOutputStream out = new HashingOutputStream(hashFunction, buffer); out.write(b); verify(hashFunction).newHasher(); verify(hasher).putByte((byte) b); verifyNoMoreInteractions(hashFunction, hasher); }
OutputStream os = outputStream; for (HashType hashType : HashType.values()) { os = new HashingOutputStream(hashType.getHashAlgorithm().function(), os); hashingStreams.put(hashType.getHashAlgorithm(), (HashingOutputStream) os); hashCodes.put(entry.getKey(), entry.getValue().hash());
public void testChecksForNull() throws Exception { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicInstanceMethods( new HashingOutputStream(Hashing.md5(), new ByteArrayOutputStream())); tester.testAllPublicStaticMethods(HashingOutputStream.class); tester.testAllPublicConstructors(HashingOutputStream.class); } }
public void testHash_hashesCorrectly() throws Exception { byte[] buf = new byte[] {'y', 'a', 'm', 's'}; HashCode expectedHash = Hashing.md5().hashBytes(buf); HashingOutputStream out = new HashingOutputStream(Hashing.md5(), buffer); out.write(buf); assertEquals(expectedHash, out.hash()); }
public void testWrite_putByteArray() throws Exception { byte[] buf = new byte[] {'y', 'a', 'm', 's'}; HashingOutputStream out = new HashingOutputStream(hashFunction, buffer); out.write(buf); verify(hashFunction).newHasher(); verify(hasher).putBytes(buf, 0, buf.length); verifyNoMoreInteractions(hashFunction, hasher); }
public void testWrite_putSingleByte() throws Exception { int b = 'q'; HashingOutputStream out = new HashingOutputStream(hashFunction, buffer); out.write(b); verify(hashFunction).newHasher(); verify(hasher).putByte((byte) b); verifyNoMoreInteractions(hashFunction, hasher); }
public void testWrite_putByteArray() throws Exception { byte[] buf = new byte[] {'y', 'a', 'm', 's'}; HashingOutputStream out = new HashingOutputStream(hashFunction, buffer); out.write(buf); verify(hashFunction).newHasher(); verify(hasher).putBytes(buf, 0, buf.length); verifyNoMoreInteractions(hashFunction, hasher); }
public void testWrite_putByteArrayAtPos() throws Exception { byte[] buf = new byte[] {'y', 'a', 'm', 's'}; HashingOutputStream out = new HashingOutputStream(hashFunction, buffer); out.write(buf, 0, 3); verify(hashFunction).newHasher(); verify(hasher).putBytes(buf, 0, 3); verifyNoMoreInteractions(hashFunction, hasher); }