if (read == 0) return null;
return new ByteList(buf.array(), 0, buf.position());
} catch (BadDescriptorException e) {
throw runtime.newIOError("bad descriptor");
} catch (IOException e) {
// All errors to sysread should be SystemCallErrors, but on a closed stream
// Ruby returns an IOError. Java throws same exception for all errors so
// we resort to this hack...