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);