int (byte[] bytes, int offset, int length) { if (!buffer.hasRemaining()) { return -1; } int actualLength = Math.min(length, buffer.remaining()); buffer.get(bytes, offset, actualLength); return actualLength; }