alexandroid/decompiled/jadx/sources/com/google/protobuf/IterableByteBufferInputStream.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

102 lines
3.4 KiB
Java

package com.google.protobuf;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Iterator;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes8.dex */
class IterableByteBufferInputStream extends InputStream {
private long currentAddress;
private byte[] currentArray;
private int currentArrayOffset;
private ByteBuffer currentByteBuffer;
private int currentByteBufferPos;
private int currentIndex;
private int dataSize = 0;
private boolean hasArray;
private Iterator<ByteBuffer> iterator;
public IterableByteBufferInputStream(Iterable<ByteBuffer> iterable) {
this.iterator = iterable.iterator();
for (ByteBuffer byteBuffer : iterable) {
this.dataSize++;
}
this.currentIndex = -1;
if (getNextByteBuffer()) {
return;
}
this.currentByteBuffer = Internal.EMPTY_BYTE_BUFFER;
this.currentIndex = 0;
this.currentByteBufferPos = 0;
this.currentAddress = 0L;
}
private boolean getNextByteBuffer() {
this.currentIndex++;
if (!this.iterator.hasNext()) {
return false;
}
ByteBuffer next = this.iterator.next();
this.currentByteBuffer = next;
this.currentByteBufferPos = next.position();
if (this.currentByteBuffer.hasArray()) {
this.hasArray = true;
this.currentArray = this.currentByteBuffer.array();
this.currentArrayOffset = this.currentByteBuffer.arrayOffset();
} else {
this.hasArray = false;
this.currentAddress = UnsafeUtil.addressOffset(this.currentByteBuffer);
this.currentArray = null;
}
return true;
}
private void updateCurrentByteBufferPos(int i) {
int i2 = this.currentByteBufferPos + i;
this.currentByteBufferPos = i2;
if (i2 == this.currentByteBuffer.limit()) {
getNextByteBuffer();
}
}
@Override // java.io.InputStream
public int read(byte[] bArr, int i, int i2) throws IOException {
if (this.currentIndex == this.dataSize) {
return -1;
}
int limit = this.currentByteBuffer.limit();
int i3 = this.currentByteBufferPos;
int i4 = limit - i3;
if (i2 > i4) {
i2 = i4;
}
if (this.hasArray) {
System.arraycopy(this.currentArray, i3 + this.currentArrayOffset, bArr, i, i2);
updateCurrentByteBufferPos(i2);
return i2;
}
int position = this.currentByteBuffer.position();
this.currentByteBuffer.position(this.currentByteBufferPos);
this.currentByteBuffer.get(bArr, i, i2);
this.currentByteBuffer.position(position);
updateCurrentByteBufferPos(i2);
return i2;
}
@Override // java.io.InputStream
public int read() throws IOException {
if (this.currentIndex == this.dataSize) {
return -1;
}
if (this.hasArray) {
int i = this.currentArray[this.currentByteBufferPos + this.currentArrayOffset] & 255;
updateCurrentByteBufferPos(1);
return i;
}
int i2 = UnsafeUtil.getByte(this.currentByteBufferPos + this.currentAddress) & 255;
updateCurrentByteBufferPos(1);
return i2;
}
}