final int available = stream.bufferedInputBytesRemaining();
if (available >= len) {
return stream.copyBufferedBytes(bytes, off, len);
} else if (stream.getDescriptor().getChannel() instanceof SelectableChannel) {
SelectableChannel ch = (SelectableChannel) stream.getDescriptor().getChannel();
synchronized (ch.blockingLock()) {
boolean oldBlocking = ch.isBlocking();
try {
if (!oldBlocking) {
ch.configureBlocking(true);
}