diff --git a/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java b/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java index e4a7f85268..76a623f07f 100644 --- a/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java +++ b/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java @@ -152,6 +152,9 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer { } public void getBytes(int index, ChannelBuffer dst, int length) { + if (length > dst.writableBytes()) { + throw new IndexOutOfBoundsException(); + } getBytes(index, dst, dst.writerIndex(), length); dst.writerIndex(dst.writerIndex() + length); } @@ -165,6 +168,9 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer { } public void setBytes(int index, ChannelBuffer src, int length) { + if (length > src.readableBytes()) { + throw new IndexOutOfBoundsException(); + } setBytes(index, src, src.readerIndex(), length); src.readerIndex(src.readerIndex() + length); } diff --git a/src/main/java/org/jboss/netty/buffer/ChannelBuffer.java b/src/main/java/org/jboss/netty/buffer/ChannelBuffer.java index 54430d9944..f550a567fa 100644 --- a/src/main/java/org/jboss/netty/buffer/ChannelBuffer.java +++ b/src/main/java/org/jboss/netty/buffer/ChannelBuffer.java @@ -76,15 +76,14 @@ import java.util.NoSuchElementException; * 0 <= readerIndex <= writerIndex <= capacity * * - *
* If there's not enough content left, {@link IndexOutOfBoundsException} is * raised. The default value of newly allocated, wrapped or copied buffer's @@ -134,7 +133,6 @@ import java.util.NoSuchElementException; * * +-------------------+------------------+------------------+ * | discardable bytes | readable bytes | writable bytes | - * | | (CONTENT) | | * +-------------------+------------------+------------------+ * | | | | * 0 <= readerIndex <= writerIndex <= capacity @@ -144,7 +142,6 @@ import java.util.NoSuchElementException; * * +------------------+--------------------------------------+ * | readable bytes | writable bytes (got more space) | - * | (CONTENT) | | * +------------------+--------------------------------------+ * | | | * readerIndex (0) <= writerIndex (decreased) <= capacity @@ -163,7 +160,6 @@ import java.util.NoSuchElementException; * * +-------------------+------------------+------------------+ * | discardable bytes | readable bytes | writable bytes | - * | | (CONTENT) | | * +-------------------+------------------+------------------+ * | | | | * 0 <= readerIndex <= writerIndex <= capacity @@ -200,14 +196,14 @@ import java.util.NoSuchElementException; * {@link #duplicate()}, {@link #slice()} or {@link #slice(int, int)}. * A derived buffer will have an independent {@link #readerIndex() readerIndex}, * {@link #writerIndex() writerIndex} and marker indexes, while it shares - * other internal data representation, just like a NIO {@link ByteBuffer} does. + * other internal data representation, just like a NIO buffer does. *
* In case a completely fresh copy of an existing buffer is required, please * call {@link #copy()} method instead. * *
* // No matter what the current state of the buffer is, the following @@ -333,13 +331,13 @@ public interface ChannelBuffer extends Comparable{ void setIndex(int readerIndex, int writerIndex); /** - * Returns the number of readable bytes which equals to + * Returns the number of readable bytes which is equal to * {@code (this.writerIndex - this.readerIndex)}. */ int readableBytes(); /** - * Returns the number of writable bytes which equals to + * Returns the number of writable bytes which is equal to * {@code (this.capacity - this.writerIndex)}. */ int writableBytes(); @@ -364,7 +362,7 @@ public interface ChannelBuffer extends Comparable { * This method is identical to {@link #setIndex(int, int) setIndex(0, 0)}. * * Please note that the behavior of this method is different - * from that of NIO {@link ByteBuffer}, which sets the {@code limit} to + * from that of NIO buffer, which sets the {@code limit} to * the {@code capacity} of the buffer. */ void clear();