package okhttp3.internal.cache2;

import c.q.d.j;
import d.f;
import java.io.IOException;
import java.nio.channels.FileChannel;

/* JADX INFO: compiled from: FileOperator.kt */
/* JADX INFO: loaded from: classes.dex */
public final class FileOperator {
    private final FileChannel fileChannel;

    public FileOperator(FileChannel fileChannel) {
        j.c(fileChannel, "fileChannel");
        this.fileChannel = fileChannel;
    }

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

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