package okhttp3.internal.cache2;

import h.i;
import h.x.d.k;
import i.f;
import java.io.IOException;
import java.nio.channels.FileChannel;

/* JADX INFO: compiled from: FileOperator.kt */
/* JADX INFO: loaded from: classes.dex */
@i(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;", "", "pos", "Lokio/Buffer;", "sink", "byteCount", "", "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 = "", xi = 0, xs = "")
public final class FileOperator {
    private final FileChannel fileChannel;

    public FileOperator(FileChannel fileChannel) {
        k.d(fileChannel, "fileChannel");
        this.fileChannel = fileChannel;
    }

    public final void read(long j2, f fVar, long j3) throws IOException {
        k.d(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 {
        k.d(fVar, "source");
        if (j3 < 0 || j3 > fVar.J()) {
            throw new IndexOutOfBoundsException();
        }
        long j4 = j2;
        long j5 = j3;
        while (j5 > 0) {
            long jTransferFrom = this.fileChannel.transferFrom(fVar, j4, j5);
            j4 += jTransferFrom;
            j5 -= jTransferFrom;
        }
    }
}
