try {
OpenFile openFile = ((RubyIO) src).getOpenFile();
openFile.checkClosed(runtime);
openFile.checkReadable(runtime);
ChannelStream stream = (ChannelStream) openFile.getMainStreamSafe();
ByteBuffer buffer = ((AbstractMemory) dst).getMemoryIO().asByteBuffer();
int count = RubyNumeric.num2int(rbLength);
if (count > buffer.remaining()) {
throw runtime.newIndexError("read count too big for output buffer");
}
if (count < buffer.remaining()) {
buffer = buffer.duplicate();
buffer.limit(count);
}
return runtime.newFixnum(stream.read(buffer));
} catch (InvalidValueException ex) {
throw runtime.newErrnoEINVALError();
} catch (EOFException e) {
return runtime.newFixnum(-1);