package ei;

import java.io.IOException;
import java.io.InputStream;
import java.util.Queue;

/* loaded from: classes4.dex */
public final class d extends InputStream {

    /* renamed from: r, reason: collision with root package name */
    private static final Queue f17173r = l.e(0);

    /* renamed from: p, reason: collision with root package name */
    private InputStream f17174p;

    /* renamed from: q, reason: collision with root package name */
    private IOException f17175q;

    d() {
    }

    public static d b(InputStream inputStream) {
        d dVar;
        Queue queue = f17173r;
        synchronized (queue) {
            dVar = (d) queue.poll();
        }
        if (dVar == null) {
            dVar = new d();
        }
        dVar.c(inputStream);
        return dVar;
    }

    public IOException a() {
        return this.f17175q;
    }

    @Override // java.io.InputStream
    public int available() {
        return this.f17174p.available();
    }

    void c(InputStream inputStream) {
        this.f17174p = inputStream;
    }

    @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        this.f17174p.close();
    }

    @Override // java.io.InputStream
    public void mark(int i10) {
        this.f17174p.mark(i10);
    }

    @Override // java.io.InputStream
    public boolean markSupported() {
        return this.f17174p.markSupported();
    }

    @Override // java.io.InputStream
    public int read() {
        try {
            return this.f17174p.read();
        } catch (IOException e10) {
            this.f17175q = e10;
            throw e10;
        }
    }

    public void release() {
        this.f17175q = null;
        this.f17174p = null;
        Queue queue = f17173r;
        synchronized (queue) {
            queue.offer(this);
        }
    }

    @Override // java.io.InputStream
    public synchronized void reset() {
        this.f17174p.reset();
    }

    @Override // java.io.InputStream
    public long skip(long j10) {
        try {
            return this.f17174p.skip(j10);
        } catch (IOException e10) {
            this.f17175q = e10;
            throw e10;
        }
    }

    @Override // java.io.InputStream
    public int read(byte[] bArr) {
        try {
            return this.f17174p.read(bArr);
        } catch (IOException e10) {
            this.f17175q = e10;
            throw e10;
        }
    }

    @Override // java.io.InputStream
    public int read(byte[] bArr, int i10, int i11) {
        try {
            return this.f17174p.read(bArr, i10, i11);
        } catch (IOException e10) {
            this.f17175q = e10;
            throw e10;
        }
    }
}
