@Override HashCode makeHash(Hasher[] hashers) { byte[] bytes = new byte[bits() / 8]; int i = 0; for (Hasher hasher : hashers) { HashCode newHash = hasher.hash(); i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8); } return HashCode.fromBytesNoCopy(bytes); }
public void testWriteBytesToUndersizedArrayLongMaxLength() { byte[] dest = new byte[3]; try { HASH_ABCD.writeBytesTo(dest, 0, 5); fail(); } catch (IndexOutOfBoundsException expected) { } }
public void testWriteBytesToOversizedArrayLongMaxLength() { byte[] dest = new byte[5]; HASH_ABCD.writeBytesTo(dest, 0, 5); assertTrue( Arrays.equals( new byte[] {(byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd, (byte) 0x00}, dest)); }
public void testWriteBytesToOversizedArray() { byte[] dest = new byte[5]; HASH_ABCD.writeBytesTo(dest, 0, 4); assertTrue( Arrays.equals( new byte[] {(byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd, (byte) 0x00}, dest)); }
public void testWriteBytesTo() { byte[] dest = new byte[4]; HASH_ABCD.writeBytesTo(dest, 0, 4); assertTrue( Arrays.equals(new byte[] {(byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd}, dest)); }
public void testWriteBytesToOversizedArrayShortMaxLength() { byte[] dest = new byte[5]; HASH_ABCD.writeBytesTo(dest, 0, 3); assertTrue( Arrays.equals( new byte[] {(byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0x00, (byte) 0x00}, dest)); }
public void testWriteBytesToUndersizedArray() { byte[] dest = new byte[3]; try { HASH_ABCD.writeBytesTo(dest, 0, 4); fail(); } catch (IndexOutOfBoundsException expected) { } }
public void testWriteBytesToUndersizedArrayShortMaxLength() { byte[] dest = new byte[3]; HASH_ABCD.writeBytesTo(dest, 0, 2); assertTrue(Arrays.equals(new byte[] {(byte) 0xaa, (byte) 0xbb, (byte) 0x00}, dest)); }
@Override HashCode makeHash(Hasher[] hashers) { byte[] bytes = new byte[bits() / 8]; int i = 0; for (Hasher hasher : hashers) { HashCode newHash = hasher.hash(); i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8); } return HashCode.fromBytesNoCopy(bytes); }
@Override HashCode makeHash(Hasher[] hashers) { byte[] bytes = new byte[bits() / 8]; int i = 0; for (Hasher hasher : hashers) { HashCode newHash = hasher.hash(); i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8); } return HashCode.fromBytesNoCopy(bytes); }
public void testIntWriteBytesTo() { byte[] dest = new byte[4]; HashCode.fromInt(42).writeBytesTo(dest, 0, 4); assertTrue(Arrays.equals(HashCode.fromInt(42).asBytes(), dest)); }
public void testLongWriteBytesTo() { byte[] dest = new byte[8]; HashCode.fromLong(42).writeBytesTo(dest, 0, 8); assertTrue(Arrays.equals(HashCode.fromLong(42).asBytes(), dest)); }
private static void assertReadableBytes(HashCode hashCode) { assertTrue(hashCode.bits() >= 32); // sanity byte[] hashBytes = hashCode.asBytes(); int totalBytes = hashCode.bits() / 8; for (int bytes = 0; bytes < totalBytes; bytes++) { byte[] bb = new byte[bytes]; hashCode.writeBytesTo(bb, 0, bb.length); assertTrue(Arrays.equals(Arrays.copyOf(hashBytes, bytes), bb)); } }
private static void assertExpectedHashCode(ExpectedHashCode expectedHashCode, HashCode hash) { assertTrue(Arrays.equals(expectedHashCode.bytes, hash.asBytes())); byte[] bb = new byte[hash.bits() / 8]; hash.writeBytesTo(bb, 0, bb.length); assertTrue(Arrays.equals(expectedHashCode.bytes, bb)); assertEquals(expectedHashCode.asInt, hash.asInt()); if (expectedHashCode.asLong == null) { try { hash.asLong(); fail(); } catch (IllegalStateException expected) { } } else { assertEquals(expectedHashCode.asLong.longValue(), hash.asLong()); } assertEquals(expectedHashCode.toString, hash.toString()); assertSideEffectFree(hash); assertReadableBytes(hash); }
@Override HashCode makeHash(Hasher[] hashers) { byte[] bytes = new byte[bits / 8]; int i = 0; for (Hasher hasher : hashers) { HashCode newHash = hasher.hash(); i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8); } return HashCode.fromBytesNoCopy(bytes); }
@Override HashCode makeHash(Hasher[] hashers) { byte[] bytes = new byte[bits / 8]; int i = 0; for (Hasher hasher : hashers) { HashCode newHash = hasher.hash(); i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8); } return HashCode.fromBytesNoCopy(bytes); }
@Override HashCode makeHash(Hasher[] hashers) { byte[] bytes = new byte[bits() / 8]; int i = 0; for (Hasher hasher : hashers) { HashCode newHash = hasher.hash(); i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8); } return HashCode.fromBytesNoCopy(bytes); }
@Override public UUID hash(@NonNull ArrayView key) { byte[] rawHash = new byte[HASH_SIZE_BYTES]; int c = HASH.hashBytes(key.array(), key.arrayOffset(), key.getLength()).writeBytesTo(rawHash, 0, rawHash.length); assert c == rawHash.length; return toUUID(rawHash); } }
public void testWriteBytesToOversizedArrayLongMaxLength() { byte[] dest = new byte[5]; HASH_ABCD.writeBytesTo(dest, 0, 5); assertTrue(Arrays.equals( new byte[] { (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd, (byte) 0x00 }, dest)); }
public void testLongWriteBytesTo() { byte[] dest = new byte[8]; HashCode.fromLong(42).writeBytesTo(dest, 0, 8); assertTrue(Arrays.equals( HashCode.fromLong(42).asBytes(), dest)); }