package p5;

import java.io.Closeable;
import java.util.concurrent.locks.ReentrantLock;

/* JADX INFO: renamed from: p5.q, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC2747q implements Closeable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final boolean f23111a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f23112b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f23113c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final ReentrantLock f23114d = new ReentrantLock();

    public AbstractC2747q(boolean z6) {
        this.f23111a = z6;
    }

    public static C2745o g(AbstractC2747q abstractC2747q) {
        if (!abstractC2747q.f23111a) {
            throw new IllegalStateException("file handle is read-only");
        }
        ReentrantLock reentrantLock = abstractC2747q.f23114d;
        reentrantLock.lock();
        try {
            if (abstractC2747q.f23112b) {
                throw new IllegalStateException("closed");
            }
            abstractC2747q.f23113c++;
            reentrantLock.unlock();
            return new C2745o(abstractC2747q);
        } catch (Throwable th) {
            reentrantLock.unlock();
            throw th;
        }
    }

    public abstract void a();

    public abstract void b();

    public abstract int c(long j4, byte[] bArr, int i6, int i7);

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        ReentrantLock reentrantLock = this.f23114d;
        reentrantLock.lock();
        try {
            if (this.f23112b) {
                return;
            }
            this.f23112b = true;
            if (this.f23113c != 0) {
                return;
            }
            reentrantLock.unlock();
            a();
        } finally {
            reentrantLock.unlock();
        }
    }

    public abstract long d();

    public abstract void f(long j4, byte[] bArr, int i6, int i7);

    public final void flush() {
        if (!this.f23111a) {
            throw new IllegalStateException("file handle is read-only");
        }
        ReentrantLock reentrantLock = this.f23114d;
        reentrantLock.lock();
        try {
            if (this.f23112b) {
                throw new IllegalStateException("closed");
            }
            reentrantLock.unlock();
            b();
        } catch (Throwable th) {
            reentrantLock.unlock();
            throw th;
        }
    }

    public final long i() {
        ReentrantLock reentrantLock = this.f23114d;
        reentrantLock.lock();
        try {
            if (this.f23112b) {
                throw new IllegalStateException("closed");
            }
            reentrantLock.unlock();
            return d();
        } catch (Throwable th) {
            reentrantLock.unlock();
            throw th;
        }
    }

    public final C2746p t(long j4) {
        ReentrantLock reentrantLock = this.f23114d;
        reentrantLock.lock();
        try {
            if (this.f23112b) {
                throw new IllegalStateException("closed");
            }
            this.f23113c++;
            reentrantLock.unlock();
            return new C2746p(this, j4);
        } catch (Throwable th) {
            reentrantLock.unlock();
            throw th;
        }
    }
}
