package defpackage;

import java.io.EOFException;
import java.io.InterruptedIOException;
import java.util.Arrays;

/* renamed from: ːʚᵗ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1938 implements InterfaceC1383 {

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

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

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

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public byte[] f7802 = new byte[65536];

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final byte[] f7803 = new byte[4096];

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public long f7804;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final long f7805;

    static {
        AbstractC2483.m6325("media3.extractor");
    }

    public C1938(InterfaceC1463 interfaceC1463, long j, long j2) {
        this.f7801 = interfaceC1463;
        this.f7804 = j;
        this.f7805 = j2;
    }

    @Override // defpackage.InterfaceC1383
    public final long getLength() {
        return this.f7805;
    }

    @Override // defpackage.InterfaceC1383
    public final long getPosition() {
        return this.f7804;
    }

    @Override // defpackage.InterfaceC1463
    public final int read(byte[] bArr, int i, int i2) throws EOFException, InterruptedIOException {
        C1938 c1938;
        int i3 = this.f7799;
        int iM5453 = 0;
        if (i3 != 0) {
            int iMin = Math.min(i3, i2);
            System.arraycopy(this.f7802, 0, bArr, i, iMin);
            m5456(iMin);
            iM5453 = iMin;
        }
        if (iM5453 == 0) {
            c1938 = this;
            iM5453 = c1938.m5453(bArr, i, i2, 0, true);
        } else {
            c1938 = this;
        }
        if (iM5453 != -1) {
            c1938.f7804 += iM5453;
        }
        return iM5453;
    }

    @Override // defpackage.InterfaceC1383
    public final void readFully(byte[] bArr, int i, int i2) throws EOFException, InterruptedIOException {
        mo4252(bArr, i, i2, false);
    }

    @Override // defpackage.InterfaceC1383
    /* renamed from: ˌʾˀ */
    public final int mo4243(int i) throws EOFException, InterruptedIOException {
        C1938 c1938;
        int iMin = Math.min(this.f7799, i);
        m5456(iMin);
        if (iMin == 0) {
            byte[] bArr = this.f7803;
            c1938 = this;
            iMin = c1938.m5453(bArr, 0, Math.min(i, bArr.length), 0, true);
        } else {
            c1938 = this;
        }
        if (iMin != -1) {
            c1938.f7804 += iMin;
        }
        return iMin;
    }

    @Override // defpackage.InterfaceC1383
    /* renamed from: ˌᵜᵹᵩ */
    public final long mo4244() {
        return this.f7804 + this.f7800;
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final int m5453(byte[] bArr, int i, int i2, int i3, boolean z) throws EOFException, InterruptedIOException {
        if (Thread.interrupted()) {
            throw new InterruptedIOException();
        }
        int i4 = this.f7801.read(bArr, i + i3, i2 - i3);
        if (i4 != -1) {
            return i3 + i4;
        }
        if (i3 == 0 && z) {
            return -1;
        }
        throw new EOFException();
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final void m5454(int i) {
        int i2 = this.f7800 + i;
        byte[] bArr = this.f7802;
        if (i2 > bArr.length) {
            this.f7802 = Arrays.copyOf(this.f7802, AbstractC3558.m8150(bArr.length * 2, 65536 + i2, i2 + 524288));
        }
    }

    @Override // defpackage.InterfaceC1383
    /* renamed from: ˑᵱ */
    public final void mo4245() {
        this.f7800 = 0;
    }

    @Override // defpackage.InterfaceC1383
    /* renamed from: ᵝᵵᵺ */
    public final boolean mo4246(int i, boolean z) throws EOFException, InterruptedIOException {
        int iMin = Math.min(this.f7799, i);
        m5456(iMin);
        int iM5453 = iMin;
        while (iM5453 < i && iM5453 != -1) {
            byte[] bArr = this.f7803;
            iM5453 = m5453(bArr, -iM5453, Math.min(i, bArr.length + iM5453), iM5453, z);
        }
        if (iM5453 != -1) {
            this.f7804 += iM5453;
        }
        return iM5453 != -1;
    }

    @Override // defpackage.InterfaceC1383
    /* renamed from: ᵡʠ */
    public final int mo4247(byte[] bArr, int i, int i2) throws EOFException, InterruptedIOException {
        C1938 c1938;
        int iMin;
        m5454(i2);
        int i3 = this.f7799;
        int i4 = this.f7800;
        int i5 = i3 - i4;
        if (i5 == 0) {
            c1938 = this;
            iMin = c1938.m5453(this.f7802, i4, i2, 0, true);
            if (iMin == -1) {
                return -1;
            }
            c1938.f7799 += iMin;
        } else {
            c1938 = this;
            iMin = Math.min(i2, i5);
        }
        System.arraycopy(c1938.f7802, c1938.f7800, bArr, i, iMin);
        c1938.f7800 += iMin;
        return iMin;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final boolean m5455(int i, boolean z) throws EOFException, InterruptedIOException {
        m5454(i);
        int iM5453 = this.f7799 - this.f7800;
        while (iM5453 < i) {
            C1938 c1938 = this;
            int i2 = i;
            boolean z2 = z;
            iM5453 = c1938.m5453(this.f7802, this.f7800, i2, iM5453, z2);
            if (iM5453 == -1) {
                return false;
            }
            c1938.f7799 = c1938.f7800 + iM5453;
            this = c1938;
            i = i2;
            z = z2;
        }
        this.f7800 += i;
        return true;
    }

    @Override // defpackage.InterfaceC1383
    /* renamed from: ᵧᵾˀˈ */
    public final void mo4248(int i) throws EOFException, InterruptedIOException {
        mo4246(i, false);
    }

    @Override // defpackage.InterfaceC1383
    /* renamed from: ᵮᵠـˌ */
    public final void mo4249(byte[] bArr, int i, int i2) {
        mo4251(bArr, i, i2, false);
    }

    @Override // defpackage.InterfaceC1383
    /* renamed from: ᵳٴᵶ */
    public final void mo4250(int i) throws EOFException, InterruptedIOException {
        m5455(i, false);
    }

    @Override // defpackage.InterfaceC1383
    /* renamed from: ᵶᵷᵕ */
    public final boolean mo4251(byte[] bArr, int i, int i2, boolean z) {
        if (!m5455(i2, z)) {
            return false;
        }
        System.arraycopy(this.f7802, this.f7800 - i2, bArr, i, i2);
        return true;
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final void m5456(int i) {
        int i2 = this.f7799 - i;
        this.f7799 = i2;
        this.f7800 = 0;
        byte[] bArr = this.f7802;
        byte[] bArr2 = i2 < bArr.length - 524288 ? new byte[65536 + i2] : bArr;
        System.arraycopy(bArr, i, bArr2, 0, i2);
        this.f7802 = bArr2;
    }

    @Override // defpackage.InterfaceC1383
    /* renamed from: ᵻᵢﹳᵰ */
    public final boolean mo4252(byte[] bArr, int i, int i2, boolean z) throws EOFException, InterruptedIOException {
        int iMin;
        int i3 = this.f7799;
        if (i3 == 0) {
            iMin = 0;
        } else {
            iMin = Math.min(i3, i2);
            System.arraycopy(this.f7802, 0, bArr, i, iMin);
            m5456(iMin);
        }
        int iM5453 = iMin;
        while (iM5453 < i2 && iM5453 != -1) {
            iM5453 = m5453(bArr, i, i2, iM5453, z);
        }
        if (iM5453 != -1) {
            this.f7804 += iM5453;
        }
        return iM5453 != -1;
    }
}
