alexandroid/decompiled/jadx/sources/com/google/common/io/ReaderInputStream.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

214 lines
7.4 KiB
Java

package com.google.common.io;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedBytes;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharsetEncoder;
import java.util.Arrays;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@J2ktIncompatible
@GwtIncompatible
/* loaded from: classes8.dex */
final class ReaderInputStream extends InputStream {
private ByteBuffer byteBuffer;
private CharBuffer charBuffer;
private boolean doneFlushing;
private boolean draining;
private final CharsetEncoder encoder;
private boolean endOfInput;
private final Reader reader;
private final byte[] singleByte;
public ReaderInputStream(Reader reader, CharsetEncoder charsetEncoder, int i) {
this.singleByte = new byte[1];
this.reader = (Reader) Preconditions.checkNotNull(reader);
this.encoder = (CharsetEncoder) Preconditions.checkNotNull(charsetEncoder);
Preconditions.checkArgument(i > 0, "bufferSize must be positive: %s", i);
charsetEncoder.reset();
CharBuffer allocate = CharBuffer.allocate(i);
this.charBuffer = allocate;
Java8Compatibility.flip(allocate);
this.byteBuffer = ByteBuffer.allocate(i);
}
private static int availableCapacity(Buffer buffer) {
return buffer.capacity() - buffer.limit();
}
private int drain(byte[] bArr, int i, int i2) {
int min = Math.min(i2, this.byteBuffer.remaining());
this.byteBuffer.get(bArr, i, min);
return min;
}
private static CharBuffer grow(CharBuffer charBuffer) {
CharBuffer wrap = CharBuffer.wrap(Arrays.copyOf(charBuffer.array(), charBuffer.capacity() * 2));
Java8Compatibility.position(wrap, charBuffer.position());
Java8Compatibility.limit(wrap, charBuffer.limit());
return wrap;
}
private void readMoreChars() throws IOException {
if (availableCapacity(this.charBuffer) == 0) {
int position = this.charBuffer.position();
CharBuffer charBuffer = this.charBuffer;
if (position > 0) {
Java8Compatibility.flip(charBuffer.compact());
} else {
this.charBuffer = grow(charBuffer);
}
}
int limit = this.charBuffer.limit();
int read = this.reader.read(this.charBuffer.array(), limit, availableCapacity(this.charBuffer));
if (read == -1) {
this.endOfInput = true;
} else {
Java8Compatibility.limit(this.charBuffer, limit + read);
}
}
private void startDraining(boolean z) {
Java8Compatibility.flip(this.byteBuffer);
if (z && this.byteBuffer.remaining() == 0) {
this.byteBuffer = ByteBuffer.allocate(this.byteBuffer.capacity() * 2);
} else {
this.draining = true;
}
}
@Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
public void close() throws IOException {
this.reader.close();
}
/* JADX WARN: Code restructure failed: missing block: B:14:0x0029, code lost:
if (r2 <= 0) goto L16;
*/
/* JADX WARN: Code restructure failed: missing block: B:15:0x002b, code lost:
return r2;
*/
/* JADX WARN: Code restructure failed: missing block: B:16:0x002c, code lost:
return -1;
*/
@Override // java.io.InputStream
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public int read(byte[] r8, int r9, int r10) throws java.io.IOException {
/*
r7 = this;
int r0 = r9 + r10
int r1 = r8.length
com.google.common.base.Preconditions.checkPositionIndexes(r9, r0, r1)
r0 = 0
if (r10 != 0) goto La
return r0
La:
boolean r1 = r7.endOfInput
r2 = r0
Ld:
boolean r3 = r7.draining
if (r3 == 0) goto L2e
int r3 = r9 + r2
int r4 = r10 - r2
int r3 = r7.drain(r8, r3, r4)
int r2 = r2 + r3
if (r2 == r10) goto L29
boolean r3 = r7.doneFlushing
if (r3 == 0) goto L21
goto L29
L21:
r7.draining = r0
java.nio.ByteBuffer r3 = r7.byteBuffer
com.google.common.io.Java8Compatibility.clear(r3)
goto L2e
L29:
if (r2 <= 0) goto L2c
return r2
L2c:
r7 = -1
return r7
L2e:
boolean r3 = r7.doneFlushing
if (r3 == 0) goto L35
java.nio.charset.CoderResult r3 = java.nio.charset.CoderResult.UNDERFLOW
goto L4a
L35:
java.nio.charset.CharsetEncoder r3 = r7.encoder
if (r1 == 0) goto L40
java.nio.ByteBuffer r4 = r7.byteBuffer
java.nio.charset.CoderResult r3 = r3.flush(r4)
goto L4a
L40:
java.nio.CharBuffer r4 = r7.charBuffer
java.nio.ByteBuffer r5 = r7.byteBuffer
boolean r6 = r7.endOfInput
java.nio.charset.CoderResult r3 = r3.encode(r4, r5, r6)
L4a:
boolean r4 = r3.isOverflow()
r5 = 1
if (r4 == 0) goto L55
r7.startDraining(r5)
goto Ld
L55:
boolean r4 = r3.isUnderflow()
if (r4 == 0) goto L6d
if (r1 == 0) goto L63
r7.doneFlushing = r5
r7.startDraining(r0)
goto Ld
L63:
boolean r3 = r7.endOfInput
if (r3 == 0) goto L69
r1 = r5
goto L2e
L69:
r7.readMoreChars()
goto L2e
L6d:
boolean r4 = r3.isError()
if (r4 == 0) goto L2e
r3.throwException()
return r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.io.ReaderInputStream.read(byte[], int, int):int");
}
/* JADX WARN: Illegal instructions before constructor call */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public ReaderInputStream(java.io.Reader r2, java.nio.charset.Charset r3, int r4) {
/*
r1 = this;
java.nio.charset.CharsetEncoder r3 = r3.newEncoder()
java.nio.charset.CodingErrorAction r0 = java.nio.charset.CodingErrorAction.REPLACE
java.nio.charset.CharsetEncoder r3 = r3.onMalformedInput(r0)
java.nio.charset.CharsetEncoder r3 = r3.onUnmappableCharacter(r0)
r1.<init>(r2, r3, r4)
return
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.io.ReaderInputStream.<init>(java.io.Reader, java.nio.charset.Charset, int):void");
}
@Override // java.io.InputStream
public int read() throws IOException {
if (read(this.singleByte) == 1) {
return UnsignedBytes.toInt(this.singleByte[0]);
}
return -1;
}
}