what-the-bank/sources/com/google/common/hash/AbstractNonStreamingHashFun...

116 lines
4.6 KiB
Java

package com.google.common.hash;
import com.google.common.base.Preconditions;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.util.Arrays;
/* loaded from: classes2.dex */
abstract class AbstractNonStreamingHashFunction extends AbstractHashFunction {
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public abstract HashCode hashBytes(byte[] bArr, int i, int i2);
@Override // com.google.common.hash.HashFunction
public Hasher newHasher() {
return newHasher(32);
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public Hasher newHasher(int i) {
Preconditions.checkArgument(i >= 0);
return new BufferingHasher(this, i);
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public HashCode hashInt(int i) {
return hashBytes(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(i).array());
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public HashCode hashLong(long j) {
return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(j).array());
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public HashCode hashUnencodedChars(CharSequence charSequence) {
int length = charSequence.length();
ByteBuffer order = ByteBuffer.allocate(length << 1).order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < length; i++) {
order.putChar(charSequence.charAt(i));
}
return hashBytes(order.array());
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public HashCode hashString(CharSequence charSequence, Charset charset) {
return hashBytes(charSequence.toString().getBytes(charset));
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public HashCode hashBytes(ByteBuffer byteBuffer) {
return newHasher(byteBuffer.remaining()).putBytes(byteBuffer).hash();
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public final class BufferingHasher extends AbstractHasher {
final ExposedByteArrayOutputStream stream;
final AbstractNonStreamingHashFunction this$0;
BufferingHasher(AbstractNonStreamingHashFunction abstractNonStreamingHashFunction, int i) {
this.this$0 = abstractNonStreamingHashFunction;
this.stream = new ExposedByteArrayOutputStream(i);
}
@Override // com.google.common.hash.PrimitiveSink
public final Hasher putByte(byte b) {
this.stream.write(b);
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.PrimitiveSink
public final Hasher putBytes(byte[] bArr, int i, int i2) {
this.stream.write(bArr, i, i2);
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.PrimitiveSink
public final Hasher putBytes(ByteBuffer byteBuffer) {
this.stream.write(byteBuffer);
return this;
}
@Override // com.google.common.hash.Hasher
public final HashCode hash() {
return this.this$0.hashBytes(this.stream.byteArray(), 0, this.stream.length());
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class ExposedByteArrayOutputStream extends ByteArrayOutputStream {
ExposedByteArrayOutputStream(int i) {
super(i);
}
final void write(ByteBuffer byteBuffer) {
int remaining = byteBuffer.remaining();
if (((ByteArrayOutputStream) this).count + remaining > ((ByteArrayOutputStream) this).buf.length) {
((ByteArrayOutputStream) this).buf = Arrays.copyOf(((ByteArrayOutputStream) this).buf, ((ByteArrayOutputStream) this).count + remaining);
}
byteBuffer.get(((ByteArrayOutputStream) this).buf, ((ByteArrayOutputStream) this).count, remaining);
((ByteArrayOutputStream) this).count += remaining;
}
final byte[] byteArray() {
return ((ByteArrayOutputStream) this).buf;
}
final int length() {
return ((ByteArrayOutputStream) this).count;
}
}
}