package defpackage;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

/* renamed from: ʾᵕʖ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C0276 extends FilterInputStream {

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final C4805 f1867;

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

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public int f1869;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public volatile byte[] f1870;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public int f1871;

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

    public C0276(InputStream inputStream, C4805 c4805) {
        super(inputStream);
        this.f1871 = -1;
        this.f1867 = c4805;
        this.f1870 = (byte[]) c4805.m10120(65536, byte[].class);
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public static void m1613() throws IOException {
        throw new IOException("BufferedInputStream is closed");
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final synchronized int available() {
        InputStream inputStream;
        inputStream = ((FilterInputStream) this).in;
        if (this.f1870 == null || inputStream == null) {
            m1613();
            throw null;
        }
        return (this.f1868 - this.f1869) + inputStream.available();
    }

    @Override // java.io.FilterInputStream, java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        if (this.f1870 != null) {
            this.f1867.m10124(this.f1870);
            this.f1870 = null;
        }
        InputStream inputStream = ((FilterInputStream) this).in;
        ((FilterInputStream) this).in = null;
        if (inputStream != null) {
            inputStream.close();
        }
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final synchronized void mark(int i) {
        this.f1872 = Math.max(this.f1872, i);
        this.f1871 = this.f1869;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final boolean markSupported() {
        return true;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final synchronized int read() {
        byte[] bArr = this.f1870;
        InputStream inputStream = ((FilterInputStream) this).in;
        if (bArr == null || inputStream == null) {
            m1613();
            throw null;
        }
        if (this.f1869 >= this.f1868 && m1615(inputStream, bArr) == -1) {
            return -1;
        }
        if (bArr != this.f1870 && (bArr = this.f1870) == null) {
            m1613();
            throw null;
        }
        int i = this.f1868;
        int i2 = this.f1869;
        if (i - i2 <= 0) {
            return -1;
        }
        this.f1869 = i2 + 1;
        return bArr[i2] & 255;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final synchronized int read(byte[] bArr, int i, int i2) {
        int i3;
        int i4;
        byte[] bArr2 = this.f1870;
        if (bArr2 == null) {
            m1613();
            throw null;
        }
        if (i2 == 0) {
            return 0;
        }
        InputStream inputStream = ((FilterInputStream) this).in;
        if (inputStream == null) {
            m1613();
            throw null;
        }
        int i5 = this.f1869;
        int i6 = this.f1868;
        if (i5 < i6) {
            int i7 = i6 - i5;
            if (i7 >= i2) {
                i7 = i2;
            }
            System.arraycopy(bArr2, i5, bArr, i, i7);
            this.f1869 += i7;
            if (i7 == i2 || inputStream.available() == 0) {
                return i7;
            }
            i += i7;
            i3 = i2 - i7;
        } else {
            i3 = i2;
        }
        while (true) {
            if (this.f1871 == -1 && i3 >= bArr2.length) {
                i4 = inputStream.read(bArr, i, i3);
                if (i4 == -1) {
                    return i3 != i2 ? i2 - i3 : -1;
                }
            } else {
                if (m1615(inputStream, bArr2) == -1) {
                    return i3 != i2 ? i2 - i3 : -1;
                }
                if (bArr2 != this.f1870 && (bArr2 = this.f1870) == null) {
                    m1613();
                    throw null;
                }
                int i8 = this.f1868;
                int i9 = this.f1869;
                i4 = i8 - i9;
                if (i4 >= i3) {
                    i4 = i3;
                }
                System.arraycopy(bArr2, i9, bArr, i, i4);
                this.f1869 += i4;
            }
            i3 -= i4;
            if (i3 == 0) {
                return i2;
            }
            if (inputStream.available() == 0) {
                return i2 - i3;
            }
            i += i4;
        }
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final synchronized void reset() {
        if (this.f1870 == null) {
            throw new IOException("Stream is closed");
        }
        int i = this.f1871;
        if (-1 == i) {
            throw new C4077("Mark has been invalidated, pos: " + this.f1869 + " markLimit: " + this.f1872);
        }
        this.f1869 = i;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final synchronized long skip(long j) {
        if (j < 1) {
            return 0L;
        }
        byte[] bArr = this.f1870;
        if (bArr == null) {
            m1613();
            throw null;
        }
        InputStream inputStream = ((FilterInputStream) this).in;
        if (inputStream == null) {
            m1613();
            throw null;
        }
        int i = this.f1868;
        int i2 = this.f1869;
        if (i - i2 >= j) {
            this.f1869 = (int) (i2 + j);
            return j;
        }
        long j2 = i - i2;
        this.f1869 = i;
        if (this.f1871 == -1 || j > this.f1872) {
            long jSkip = inputStream.skip(j - j2);
            if (jSkip > 0) {
                this.f1871 = -1;
            }
            return j2 + jSkip;
        }
        if (m1615(inputStream, bArr) == -1) {
            return j2;
        }
        int i3 = this.f1868;
        int i4 = this.f1869;
        if (i3 - i4 >= j - j2) {
            this.f1869 = (int) ((i4 + j) - j2);
            return j;
        }
        long j3 = (j2 + i3) - i4;
        this.f1869 = i3;
        return j3;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final synchronized void m1614() {
        if (this.f1870 != null) {
            this.f1867.m10124(this.f1870);
            this.f1870 = null;
        }
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final int m1615(InputStream inputStream, byte[] bArr) throws IOException {
        int i = this.f1871;
        if (i != -1) {
            int i2 = this.f1869 - i;
            int i3 = this.f1872;
            if (i2 < i3) {
                if (i == 0 && i3 > bArr.length && this.f1868 == bArr.length) {
                    int length = bArr.length * 2;
                    if (length <= i3) {
                        i3 = length;
                    }
                    byte[] bArr2 = (byte[]) this.f1867.m10120(i3, byte[].class);
                    System.arraycopy(bArr, 0, bArr2, 0, bArr.length);
                    this.f1870 = bArr2;
                    this.f1867.m10124(bArr);
                    bArr = bArr2;
                } else if (i > 0) {
                    System.arraycopy(bArr, i, bArr, 0, bArr.length - i);
                }
                int i4 = this.f1869 - this.f1871;
                this.f1869 = i4;
                this.f1871 = 0;
                this.f1868 = 0;
                int i5 = inputStream.read(bArr, i4, bArr.length - i4);
                int i6 = this.f1869;
                if (i5 > 0) {
                    i6 += i5;
                }
                this.f1868 = i6;
                return i5;
            }
        }
        int i7 = inputStream.read(bArr);
        if (i7 > 0) {
            this.f1871 = -1;
            this.f1869 = 0;
            this.f1868 = i7;
        }
        return i7;
    }
}
