package defpackage;

import java.io.IOException;
import java.io.InputStream;
import org.tukaani.xz.XZIOException;

/* JADX INFO: renamed from: ᵢˈʽ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C3266 extends InputStream {

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public static final /* synthetic */ int f12485 = 0;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public InputStream f12487;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final InterfaceC2016 f12490;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final byte[] f12489 = new byte[4096];

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public int f12491 = 0;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public int f12492 = 0;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public int f12493 = 0;

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public boolean f12486 = false;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public IOException f12488 = null;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public final byte[] f12494 = new byte[1];

    public C3266(InputStream inputStream, InterfaceC2016 interfaceC2016) {
        inputStream.getClass();
        this.f12487 = inputStream;
        this.f12490 = interfaceC2016;
    }

    @Override // java.io.InputStream
    public final int available() throws IOException {
        if (this.f12487 == null) {
            throw new XZIOException("Stream closed");
        }
        IOException iOException = this.f12488;
        if (iOException == null) {
            return this.f12492;
        }
        throw iOException;
    }

    @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        InputStream inputStream = this.f12487;
        if (inputStream != null) {
            try {
                inputStream.close();
            } finally {
                this.f12487 = null;
            }
        }
    }

    @Override // java.io.InputStream
    public final int read() {
        byte[] bArr = this.f12494;
        if (read(bArr, 0, 1) == -1) {
            return -1;
        }
        return bArr[0] & 255;
    }

    @Override // java.io.InputStream
    public final int read(byte[] bArr, int i, int i2) throws IOException {
        int i3;
        byte[] bArr2 = this.f12489;
        if (i < 0 || i2 < 0 || (i3 = i + i2) < 0 || i3 > bArr.length) {
            C4468.m9514();
            return 0;
        }
        if (i2 == 0) {
            return 0;
        }
        if (this.f12487 == null) {
            throw new XZIOException("Stream closed");
        }
        IOException iOException = this.f12488;
        if (iOException != null) {
            throw iOException;
        }
        int i4 = 0;
        while (true) {
            try {
                int iMin = Math.min(this.f12492, i2);
                System.arraycopy(bArr2, this.f12491, bArr, i, iMin);
                int i5 = this.f12491 + iMin;
                this.f12491 = i5;
                int i6 = this.f12492 - iMin;
                this.f12492 = i6;
                i += iMin;
                i2 -= iMin;
                i4 += iMin;
                int i7 = this.f12493;
                if (i5 + i6 + i7 == 4096) {
                    System.arraycopy(bArr2, i5, bArr2, 0, i6 + i7);
                    this.f12491 = 0;
                }
                if (i2 == 0 || this.f12486) {
                    break;
                }
                int i8 = this.f12491 + this.f12492 + this.f12493;
                int i9 = this.f12487.read(bArr2, i8, 4096 - i8);
                if (i9 == -1) {
                    this.f12486 = true;
                    this.f12492 = this.f12493;
                    this.f12493 = 0;
                } else {
                    int i10 = this.f12493 + i9;
                    this.f12493 = i10;
                    int iMo5393 = this.f12490.mo5393(bArr2, this.f12491, i10);
                    this.f12492 = iMo5393;
                    this.f12493 -= iMo5393;
                }
            } catch (IOException e) {
                this.f12488 = e;
                throw e;
            }
        }
        if (i4 > 0) {
            return i4;
        }
        return -1;
    }
}
