package okhttp3.internal.cache2;

import java.io.IOException;
import java.nio.channels.FileChannel;
import kotlin.jvm.internal.l;
import okio.C0688f;

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

    public FileOperator(FileChannel fileChannel) {
        l.e(fileChannel, "fileChannel");
        this.fileChannel = fileChannel;
    }

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

    public final void write(long j2, C0688f source, long j3) throws IOException {
        l.e(source, "source");
        if (j3 < 0 || j3 > source.G()) {
            throw new IndexOutOfBoundsException();
        }
        while (j3 > 0) {
            long jTransferFrom = this.fileChannel.transferFrom(source, j2, j3);
            j2 += jTransferFrom;
            j3 -= jTransferFrom;
        }
    }
}
