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;

/* JADX INFO: renamed from: ʿᵠᵬ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C0442 extends InputStream {

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public IOException f2423;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final C2470 f2424;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public final byte[] f2425;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public InputStream f2426;

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

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public C5217 f2428;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public final boolean f2429;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public boolean f2430;

    public C0442(InputStream inputStream) throws IOException {
        C2470 c2470 = C2470.f9591;
        this.f2430 = false;
        this.f2423 = null;
        this.f2425 = new byte[1];
        this.f2424 = c2470;
        this.f2426 = inputStream;
        this.f2427 = -1;
        this.f2429 = true;
        byte[] bArr = new byte[12];
        new DataInputStream(inputStream).readFully(bArr);
        this.f2428 = new C5217(inputStream, -1, true, bArr, c2470);
    }

    @Override // java.io.InputStream
    public final int available() throws IOException {
        if (this.f2426 == null) {
            throw new XZIOException("Stream closed");
        }
        IOException iOException = this.f2423;
        if (iOException != null) {
            throw iOException;
        }
        C5217 c5217 = this.f2428;
        if (c5217 == null) {
            return 0;
        }
        return c5217.available();
    }

    @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        if (this.f2426 != null) {
            C5217 c5217 = this.f2428;
            if (c5217 != null) {
                c5217.m10751(false);
                this.f2428 = null;
            }
            try {
                this.f2426.close();
            } finally {
                this.f2426 = null;
            }
        }
    }

    @Override // java.io.InputStream
    public final int read() {
        byte[] bArr = this.f2425;
        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.
    */
    public final int read(byte[] bArr, int i, int i2) throws IOException {
        int i3;
        int i4 = 0;
        if (i < 0 || i2 < 0 || (i3 = i + i2) < 0 || i3 > bArr.length) {
            C4468.m9514();
            return 0;
        }
        if (i2 == 0) {
            return 0;
        }
        if (this.f2426 == null) {
            throw new XZIOException("Stream closed");
        }
        IOException iOException = this.f2423;
        if (iOException != null) {
            throw iOException;
        }
        if (!this.f2430) {
            while (true) {
                if (i2 <= 0) {
                    break;
                }
                try {
                    if (this.f2428 == null) {
                        m1840();
                        if (this.f2430) {
                            if (i4 == 0) {
                            }
                        }
                    }
                    int i5 = this.f2428.read(bArr, i, i2);
                    if (i5 > 0) {
                        i4 += i5;
                        i += i5;
                        i2 -= i5;
                    } else if (i5 == -1) {
                        this.f2428 = null;
                    }
                } catch (IOException e) {
                    this.f2423 = e;
                    if (i4 == 0) {
                        throw e;
                    }
                }
            }
        }
        return -1;
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void m1840() throws IOException {
        DataInputStream dataInputStream = new DataInputStream(this.f2426);
        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.f2428 = new C5217(this.f2426, this.f2427, this.f2429, bArr, this.f2424);
                    return;
                } catch (XZFormatException unused) {
                    throw new CorruptedInputException("Garbage after a valid XZ Stream");
                }
            }
        }
        this.f2430 = true;
    }
}
