alexandroid/decompiled/jadx/sources/com/google/common/hash/AbstractStreamingHasher.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

154 lines
5 KiB
Java

package com.google.common.hash;
import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes8.dex */
abstract class AbstractStreamingHasher extends AbstractHasher {
private final ByteBuffer buffer;
private final int bufferSize;
private final int chunkSize;
public AbstractStreamingHasher(int i, int i2) {
Preconditions.checkArgument(i2 % i == 0);
this.buffer = ByteBuffer.allocate(i2 + 7).order(ByteOrder.LITTLE_ENDIAN);
this.bufferSize = i2;
this.chunkSize = i;
}
private void munch() {
Java8Compatibility.flip(this.buffer);
while (true) {
int remaining = this.buffer.remaining();
int i = this.chunkSize;
ByteBuffer byteBuffer = this.buffer;
if (remaining < i) {
byteBuffer.compact();
return;
}
process(byteBuffer);
}
}
private void munchIfFull() {
if (this.buffer.remaining() < 8) {
munch();
}
}
@CanIgnoreReturnValue
private Hasher putBytesInternal(ByteBuffer byteBuffer) {
if (byteBuffer.remaining() <= this.buffer.remaining()) {
this.buffer.put(byteBuffer);
munchIfFull();
return this;
}
int position = this.bufferSize - this.buffer.position();
for (int i = 0; i < position; i++) {
this.buffer.put(byteBuffer.get());
}
munch();
while (byteBuffer.remaining() >= this.chunkSize) {
process(byteBuffer);
}
this.buffer.put(byteBuffer);
return this;
}
@Override // com.google.common.hash.Hasher
public final HashCode hash() {
munch();
Java8Compatibility.flip(this.buffer);
if (this.buffer.remaining() > 0) {
processRemaining(this.buffer);
ByteBuffer byteBuffer = this.buffer;
Java8Compatibility.position(byteBuffer, byteBuffer.limit());
}
return makeHash();
}
public abstract HashCode makeHash();
public abstract void process(ByteBuffer byteBuffer);
public void processRemaining(ByteBuffer byteBuffer) {
Java8Compatibility.position(byteBuffer, byteBuffer.limit());
Java8Compatibility.limit(byteBuffer, this.chunkSize + 7);
while (true) {
int position = byteBuffer.position();
int i = this.chunkSize;
if (position >= i) {
Java8Compatibility.limit(byteBuffer, i);
Java8Compatibility.flip(byteBuffer);
process(byteBuffer);
return;
}
byteBuffer.putLong(0L);
}
}
@Override // com.google.common.hash.Hasher, com.google.common.hash.PrimitiveSink
@CanIgnoreReturnValue
public final Hasher putByte(byte b) {
this.buffer.put(b);
munchIfFull();
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.Hasher, com.google.common.hash.PrimitiveSink
@CanIgnoreReturnValue
public final Hasher putBytes(ByteBuffer byteBuffer) {
ByteOrder order = byteBuffer.order();
try {
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
return putBytesInternal(byteBuffer);
} finally {
byteBuffer.order(order);
}
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.Hasher, com.google.common.hash.PrimitiveSink
@CanIgnoreReturnValue
public final Hasher putChar(char c) {
this.buffer.putChar(c);
munchIfFull();
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.Hasher, com.google.common.hash.PrimitiveSink
@CanIgnoreReturnValue
public final Hasher putInt(int i) {
this.buffer.putInt(i);
munchIfFull();
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.Hasher, com.google.common.hash.PrimitiveSink
@CanIgnoreReturnValue
public final Hasher putLong(long j) {
this.buffer.putLong(j);
munchIfFull();
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.Hasher, com.google.common.hash.PrimitiveSink
@CanIgnoreReturnValue
public final Hasher putShort(short s) {
this.buffer.putShort(s);
munchIfFull();
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.Hasher, com.google.common.hash.PrimitiveSink
@CanIgnoreReturnValue
public final Hasher putBytes(byte[] bArr, int i, int i2) {
return putBytesInternal(ByteBuffer.wrap(bArr, i, i2).order(ByteOrder.LITTLE_ENDIAN));
}
public AbstractStreamingHasher(int i) {
this(i, i);
}
}