diff --git a/buffer/src/main/java/io/netty/buffer/ReadOnlyByteBufferBuf.java b/buffer/src/main/java/io/netty/buffer/ReadOnlyByteBufferBuf.java index 4d1de49f7b..f2994ee99e 100644 --- a/buffer/src/main/java/io/netty/buffer/ReadOnlyByteBufferBuf.java +++ b/buffer/src/main/java/io/netty/buffer/ReadOnlyByteBufferBuf.java @@ -214,12 +214,33 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf { @Override public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException { - throw new ReadOnlyBufferException(); + ensureAccessible(); + if (length == 0) { + return this; + } + + if (buffer.hasArray()) { + out.write(buffer.array(), index + buffer.arrayOffset(), length); + } else { + byte[] tmp = new byte[length]; + ByteBuffer tmpBuf = internalNioBuffer(); + tmpBuf.clear().position(index); + tmpBuf.get(tmp); + out.write(tmp); + } + return this; } @Override public int getBytes(int index, GatheringByteChannel out, int length) throws IOException { - throw new ReadOnlyBufferException(); + ensureAccessible(); + if (length == 0) { + return 0; + } + + ByteBuffer tmpBuf = internalNioBuffer(); + tmpBuf.clear().position(index).limit(index + length); + return out.write(tmpBuf); } @Override