package okhttp3.internal.cache2;

import g.h0.c.l;
import j.d;
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) {
        l.f(fileChannel, "fileChannel");
        this.fileChannel = fileChannel;
    }

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

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