package okhttp3.internal.cache2;

import j.n;
import j.p0.d.r;
import java.io.IOException;
import java.nio.channels.FileChannel;
import l.f;
import okhttp3.HttpUrl;

/* JADX INFO: compiled from: FileOperator.kt */
/* JADX INFO: loaded from: classes.dex */
@n(bv = {1, 0, 3}, d1 = {"\u0000\"\n\u0002\u0018\u0002\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0000\u0018\u0000B\u000f\u0012\u0006\u0010\f\u001a\u00020\u000b¢\u0006\u0004\b\u000e\u0010\u000fJ%\u0010\u0007\u001a\u00020\u00062\u0006\u0010\u0002\u001a\u00020\u00012\u0006\u0010\u0004\u001a\u00020\u00032\u0006\u0010\u0005\u001a\u00020\u0001¢\u0006\u0004\b\u0007\u0010\bJ%\u0010\n\u001a\u00020\u00062\u0006\u0010\u0002\u001a\u00020\u00012\u0006\u0010\t\u001a\u00020\u00032\u0006\u0010\u0005\u001a\u00020\u0001¢\u0006\u0004\b\n\u0010\bR\u0016\u0010\f\u001a\u00020\u000b8\u0002@\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\f\u0010\r¨\u0006\u0010"}, d2 = {"Lokhttp3/internal/cache2/FileOperator;", HttpUrl.FRAGMENT_ENCODE_SET, "pos", "Lokio/Buffer;", "sink", "byteCount", HttpUrl.FRAGMENT_ENCODE_SET, "read", "(JLokio/Buffer;J)V", "source", "write", "Ljava/nio/channels/FileChannel;", "fileChannel", "Ljava/nio/channels/FileChannel;", "<init>", "(Ljava/nio/channels/FileChannel;)V", "okhttp"}, k = 1, mv = {1, 1, 15}, pn = HttpUrl.FRAGMENT_ENCODE_SET, xi = 0, xs = HttpUrl.FRAGMENT_ENCODE_SET)
public final class FileOperator {
    private final FileChannel fileChannel;

    public FileOperator(FileChannel fileChannel) {
        r.g(fileChannel, "fileChannel");
        this.fileChannel = fileChannel;
    }

    public final void read(long j2, f fVar, long j3) throws IOException {
        r.g(fVar, "sink");
        if (j3 < 0) {
            throw new IndexOutOfBoundsException();
        }
        while (j3 > 0) {
            long jTransferTo = this.fileChannel.transferTo(j2, j3, fVar);
            j2 += jTransferTo;
            j3 -= jTransferTo;
        }
    }

    public final void write(long j2, f fVar, long j3) throws IOException {
        r.g(fVar, "source");
        if (j3 < 0 || j3 > fVar.K()) {
            throw new IndexOutOfBoundsException();
        }
        while (j3 > 0) {
            long jTransferFrom = this.fileChannel.transferFrom(fVar, j2, j3);
            j2 += jTransferFrom;
            j3 -= jTransferFrom;
        }
    }
}
