package p5;

import java.io.Closeable;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/* JADX INFO: loaded from: classes3.dex */
public final class A extends AbstractC2747q {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ int f23041e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Closeable f23042f;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ A(boolean z6, Closeable closeable, int i6) {
        super(z6);
        this.f23041e = i6;
        this.f23042f = closeable;
    }

    @Override // p5.AbstractC2747q
    public final synchronized void a() {
        int i6 = this.f23041e;
        synchronized (this) {
            switch (i6) {
                case 0:
                    ((RandomAccessFile) this.f23042f).close();
                    return;
                default:
                    ((FileChannel) this.f23042f).close();
                    return;
            }
        }
    }

    @Override // p5.AbstractC2747q
    public final synchronized void b() {
        int i6 = this.f23041e;
        synchronized (this) {
            switch (i6) {
                case 0:
                    ((RandomAccessFile) this.f23042f).getFD().sync();
                    return;
                default:
                    ((FileChannel) this.f23042f).force(true);
                    return;
            }
        }
    }

    @Override // p5.AbstractC2747q
    public final synchronized int c(long j4, byte[] array, int i6, int i7) {
        int i8 = this.f23041e;
        synchronized (this) {
            switch (i8) {
                case 0:
                    kotlin.jvm.internal.o.h(array, "array");
                    ((RandomAccessFile) this.f23042f).seek(j4);
                    int i9 = 0;
                    while (true) {
                        if (i9 < i7) {
                            int i10 = ((RandomAccessFile) this.f23042f).read(array, i6, i7 - i9);
                            if (i10 != -1) {
                                i9 += i10;
                            } else if (i9 == 0) {
                                return -1;
                            }
                        }
                    }
                    return i9;
                default:
                    kotlin.jvm.internal.o.h(array, "array");
                    ((FileChannel) this.f23042f).position(j4);
                    ByteBuffer byteBufferWrap = ByteBuffer.wrap(array, i6, i7);
                    int i11 = 0;
                    while (true) {
                        if (i11 < i7) {
                            int i12 = ((FileChannel) this.f23042f).read(byteBufferWrap);
                            if (i12 != -1) {
                                i11 += i12;
                            } else if (i11 == 0) {
                                return -1;
                            }
                        }
                    }
                    return i11;
            }
        }
    }

    @Override // p5.AbstractC2747q
    public final synchronized long d() {
        int i6 = this.f23041e;
        synchronized (this) {
            switch (i6) {
                case 0:
                    return ((RandomAccessFile) this.f23042f).length();
                default:
                    return ((FileChannel) this.f23042f).size();
            }
        }
    }

    @Override // p5.AbstractC2747q
    public final synchronized void f(long j4, byte[] array, int i6, int i7) {
        int i8 = this.f23041e;
        synchronized (this) {
            switch (i8) {
                case 0:
                    kotlin.jvm.internal.o.h(array, "array");
                    ((RandomAccessFile) this.f23042f).seek(j4);
                    ((RandomAccessFile) this.f23042f).write(array, i6, i7);
                    return;
                default:
                    kotlin.jvm.internal.o.h(array, "array");
                    ((FileChannel) this.f23042f).position(j4);
                    ((FileChannel) this.f23042f).write(ByteBuffer.wrap(array, i6, i7));
                    return;
            }
        }
    }
}
