package defpackage;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.tukaani.xz.CorruptedInputException;
import org.tukaani.xz.XZFormatException;
import org.tukaani.xz.XZIOException;

/* renamed from: ᵶᵰ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C4831 extends InputStream {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public IOException f17938;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final byte[] f17939;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public boolean f17940;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final int f17941;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final boolean f17942;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final C0471 f17943;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public C4758 f17944;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public InputStream f17945;

    public C4831(InputStream inputStream) throws IOException {
        C0471 c0471 = C0471.f2546;
        this.f17940 = false;
        this.f17938 = null;
        this.f17939 = new byte[1];
        this.f17943 = c0471;
        this.f17945 = inputStream;
        this.f17941 = -1;
        this.f17942 = true;
        byte[] bArr = new byte[12];
        new DataInputStream(inputStream).readFully(bArr);
        this.f17944 = new C4758(inputStream, -1, true, bArr, c0471);
    }

    @Override // java.io.InputStream
    public final int available() throws IOException {
        if (this.f17945 == null) {
            throw new XZIOException("Stream closed");
        }
        IOException iOException = this.f17938;
        if (iOException != null) {
            throw iOException;
        }
        C4758 c4758 = this.f17944;
        if (c4758 == null) {
            return 0;
        }
        return c4758.available();
    }

    @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        if (this.f17945 != null) {
            C4758 c4758 = this.f17944;
            if (c4758 != null) {
                c4758.m10043(false);
                this.f17944 = null;
            }
            try {
                this.f17945.close();
            } finally {
                this.f17945 = null;
            }
        }
    }

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

    /* JADX WARN: Code restructure failed: missing block: B:37:0x0047, code lost:
    
        return r0;
     */
    @Override // java.io.InputStream
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final int read(byte[] r4, int r5, int r6) throws java.io.IOException {
        /*
            r3 = this;
            r0 = 0
            if (r5 < 0) goto L51
            if (r6 < 0) goto L51
            int r1 = r5 + r6
            if (r1 < 0) goto L51
            int r2 = r4.length
            if (r1 > r2) goto L51
            if (r6 != 0) goto Lf
            return r0
        Lf:
            java.io.InputStream r1 = r3.f17945
            if (r1 == 0) goto L49
            java.io.IOException r1 = r3.f17938
            if (r1 != 0) goto L48
            boolean r1 = r3.f17940
            r2 = -1
            if (r1 == 0) goto L1d
            goto L2c
        L1d:
            if (r6 <= 0) goto L47
            ᵵᵼᵬ r1 = r3.f17944     // Catch: java.io.IOException -> L2d
            if (r1 != 0) goto L2f
            r3.m10160()     // Catch: java.io.IOException -> L2d
            boolean r1 = r3.f17940     // Catch: java.io.IOException -> L2d
            if (r1 == 0) goto L2f
            if (r0 != 0) goto L47
        L2c:
            return r2
        L2d:
            r4 = move-exception
            goto L41
        L2f:
            ᵵᵼᵬ r1 = r3.f17944     // Catch: java.io.IOException -> L2d
            int r1 = r1.read(r4, r5, r6)     // Catch: java.io.IOException -> L2d
            if (r1 <= 0) goto L3b
            int r0 = r0 + r1
            int r5 = r5 + r1
            int r6 = r6 - r1
            goto L1d
        L3b:
            if (r1 != r2) goto L1d
            r1 = 0
            r3.f17944 = r1     // Catch: java.io.IOException -> L2d
            goto L1d
        L41:
            r3.f17938 = r4
            if (r0 == 0) goto L46
            goto L47
        L46:
            throw r4
        L47:
            return r0
        L48:
            throw r1
        L49:
            org.tukaani.xz.XZIOException r3 = new org.tukaani.xz.XZIOException
            java.lang.String r4 = "Stream closed"
            r3.<init>(r4)
            throw r3
        L51:
            defpackage.C0190.m1431()
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C4831.read(byte[], int, int):int");
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m10160() throws IOException {
        DataInputStream dataInputStream = new DataInputStream(this.f17945);
        byte[] bArr = new byte[12];
        while (dataInputStream.read(bArr, 0, 1) != -1) {
            dataInputStream.readFully(bArr, 1, 3);
            if (bArr[0] != 0 || bArr[1] != 0 || bArr[2] != 0 || bArr[3] != 0) {
                dataInputStream.readFully(bArr, 4, 8);
                try {
                    this.f17944 = new C4758(this.f17945, this.f17941, this.f17942, bArr, this.f17943);
                    return;
                } catch (XZFormatException unused) {
                    throw new CorruptedInputException("Garbage after a valid XZ Stream");
                }
            }
        }
        this.f17940 = true;
    }
}
