本文整理了Java中com.google.common.hash.HashCode.writeBytesTo()
方法的一些代码示例,展示了HashCode.writeBytesTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashCode.writeBytesTo()
方法的具体详情如下:
包路径:com.google.common.hash.HashCode
类名称:HashCode
方法名:writeBytesTo
[英]Copies bytes from this hash code into dest.
[中]将此哈希代码中的字节复制到dest。
代码示例来源:origin: google/guava
@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);
}
代码示例来源:origin: google/guava
public void testWriteBytesToUndersizedArrayLongMaxLength() {
byte[] dest = new byte[3];
try {
HASH_ABCD.writeBytesTo(dest, 0, 5);
fail();
} catch (IndexOutOfBoundsException expected) {
}
}
代码示例来源:origin: google/guava
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));
}
代码示例来源:origin: google/guava
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));
}
代码示例来源:origin: google/guava
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));
}
代码示例来源:origin: google/guava
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));
}
代码示例来源:origin: google/guava
public void testWriteBytesToUndersizedArray() {
byte[] dest = new byte[3];
try {
HASH_ABCD.writeBytesTo(dest, 0, 4);
fail();
} catch (IndexOutOfBoundsException expected) {
}
}
代码示例来源:origin: google/guava
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));
}
代码示例来源:origin: google/j2objc
@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);
}
代码示例来源:origin: wildfly/wildfly
@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);
}
代码示例来源:origin: google/guava
public void testIntWriteBytesTo() {
byte[] dest = new byte[4];
HashCode.fromInt(42).writeBytesTo(dest, 0, 4);
assertTrue(Arrays.equals(HashCode.fromInt(42).asBytes(), dest));
}
代码示例来源:origin: google/guava
public void testLongWriteBytesTo() {
byte[] dest = new byte[8];
HashCode.fromLong(42).writeBytesTo(dest, 0, 8);
assertTrue(Arrays.equals(HashCode.fromLong(42).asBytes(), dest));
}
代码示例来源:origin: google/guava
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));
}
}
代码示例来源:origin: google/guava
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);
}
代码示例来源:origin: com.google.guava/guava-jdk5
@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);
}
代码示例来源:origin: Nextdoor/bender
@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);
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
@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);
}
代码示例来源:origin: pravega/pravega
@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);
}
}
代码示例来源:origin: com.google.guava/guava-tests
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));
}
代码示例来源:origin: com.google.guava/guava-tests
public void testLongWriteBytesTo() {
byte[] dest = new byte[8];
HashCode.fromLong(42).writeBytesTo(dest, 0, 8);
assertTrue(Arrays.equals(
HashCode.fromLong(42).asBytes(),
dest));
}
内容来源于网络,如有侵权,请联系作者删除!