public int read (byte[] bytes, int off, int len) throws IOException { Preconditions.checkNotNull(bytes, "Given byte array can not be null"); Preconditions.checkPositionIndexes(off, off + len, bytes.length); if (!buf.hasRemaining()) { return -1; } if (len == 0) { return 0; } int end = Math.min(len, buf.remaining()); buf.get(bytes, off, end); return end; } }