* Updated ChannelBuffer JavaDoc (fixes and additions)

* Changed ReplayingDecoderBuffer to reject more potentially dangerous operations
This commit is contained in:
Trustin Lee 2008-08-10 15:10:27 +00:00
parent c58e224b7e
commit a1c07e9122
2 changed files with 89 additions and 82 deletions

View File

@ -520,6 +520,24 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
*/ */
void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst);
/**
* Transfers this buffer's data to the specified destination starting at
* the specified absolute {@code index}. This method is basically same
* with {@link #getBytes(int, ChannelBuffer, int, int)}, except that this
* method increases the {@code writerIndex} of the destination by the
* number of the transferred bytes while
* {@link #getBytes(int, ChannelBuffer, int, int)} doesn't.
*
* @param length the number of bytes to transfer
*
* @throws IndexOutOfBoundsException
* if the specified {@code index} is less than {@code 0},
* if {@code index + length} is greater than
* {@code this.capacity}, or
* if {@code length} is greater than {@code dst.writableBytes}
*/
void getBytes(int index, ChannelBuffer dst, int length);
/** /**
* Transfers this buffer's data to the specified destination starting at * Transfers this buffer's data to the specified destination starting at
* the specified absolute {@code index}. * the specified absolute {@code index}.
@ -665,7 +683,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* the specified absolute {@code index} until the destination becomes * the specified absolute {@code index} until the destination becomes
* unreadable. This method is basically same with * unreadable. This method is basically same with
* {@link #setBytes(int, ChannelBuffer, int, int)}, except that this * {@link #setBytes(int, ChannelBuffer, int, int)}, except that this
* method increased the {@code readerIndex} of the source buffer by * method increases the {@code readerIndex} of the source buffer by
* the number of the transferred bytes while * the number of the transferred bytes while
* {@link #getBytes(int, ChannelBuffer, int, int)} doesn't. * {@link #getBytes(int, ChannelBuffer, int, int)} doesn't.
* *
@ -676,6 +694,24 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
*/ */
void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src);
/**
* Transfers the specified source buffer's data to this buffer starting at
* the specified absolute {@code index}. This method is basically same
* with {@link #setBytes(int, ChannelBuffer, int, int)}, except that this
* method increases the {@code readerIndex} of the source buffer by
* the number of the transferred bytes while
* {@link #getBytes(int, ChannelBuffer, int, int)} doesn't.
*
* @param length the number of bytes to transfer
*
* @throws IndexOutOfBoundsException
* if the specified {@code index} is less than {@code 0},
* if {@code index + length} is greater than
* {@code this.capacity}, or
* if {@code length} is greater than {@code src.readableBytes}
*/
void setBytes(int index, ChannelBuffer src, int length);
/** /**
* Transfers the specified source buffer's data to this buffer starting at * Transfers the specified source buffer's data to this buffer starting at
* the specified absolute {@code index}. * the specified absolute {@code index}.
@ -776,8 +812,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* the {@code readerIndex} by {@code 1} in this buffer. * the {@code readerIndex} by {@code 1} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + 1} is greater than * if {@code this.readableBytes} is less than {@code 1}
* {@code this.writerIndex}
*/ */
byte readByte(); byte readByte();
@ -786,8 +821,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* the {@code readerIndex} by {@code 1} in this buffer. * the {@code readerIndex} by {@code 1} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + 1} is greater than * if {@code this.readableBytes} is less than {@code 1}
* {@code this.writerIndex}
*/ */
short readUnsignedByte(); short readUnsignedByte();
@ -796,8 +830,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* and increases the {@code readerIndex} by {@code 2} in this buffer. * and increases the {@code readerIndex} by {@code 2} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + 2} is greater than * if {@code this.readableBytes} is less than {@code 2}
* {@code this.writerIndex}
*/ */
short readShort(); short readShort();
@ -806,8 +839,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* and increases the {@code readerIndex} by {@code 2} in this buffer. * and increases the {@code readerIndex} by {@code 2} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + 2} is greater than * if {@code this.readableBytes} is less than {@code 2}
* {@code this.writerIndex}
*/ */
int readUnsignedShort(); int readUnsignedShort();
@ -816,8 +848,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* and increases the {@code readerIndex} by {@code 3} in this buffer. * and increases the {@code readerIndex} by {@code 3} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + 3} is greater than * if {@code this.readableBytes} is less than {@code 3}
* {@code this.writerIndex}
*/ */
int readMedium(); int readMedium();
@ -826,8 +857,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* and increases the {@code readerIndex} by {@code 3} in this buffer. * and increases the {@code readerIndex} by {@code 3} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + 3} is greater than * if {@code this.readableBytes} is less than {@code 3}
* {@code this.writerIndex}
*/ */
int readUnsignedMedium(); int readUnsignedMedium();
@ -836,8 +866,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* and increases the {@code readerIndex} by {@code 4} in this buffer. * and increases the {@code readerIndex} by {@code 4} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + 4} is greater than * if {@code this.readableBytes} is less than {@code 4}
* {@code this.writerIndex}
*/ */
int readInt(); int readInt();
@ -846,8 +875,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* and increases the {@code readerIndex} by {@code 4} in this buffer. * and increases the {@code readerIndex} by {@code 4} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + 4} is greater than * if {@code this.readableBytes} is less than {@code 4}
* {@code this.writerIndex}
*/ */
long readUnsignedInt(); long readUnsignedInt();
@ -856,8 +884,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* and increases the {@code readerIndex} by {@code 8} in this buffer. * and increases the {@code readerIndex} by {@code 8} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + 8} is greater than * if {@code this.readableBytes} is less than {@code 8}
* {@code this.writerIndex}
*/ */
long readLong(); long readLong();
@ -877,8 +904,8 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* doesn't. * doesn't.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + dst.writableBytes} is greater than * if {@code dst.writableBytes} is greater than
* {@code this.writerIndex} * {@code this.readableBytes}
*/ */
void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst);
@ -892,10 +919,8 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* while {@link #readBytes(ChannelBuffer, int, int)} doesn't. * while {@link #readBytes(ChannelBuffer, int, int)} doesn't.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + length} is greater than * if {@code length} is greater than {@code this.readableBytes} or
* {@code this.writerIndex} or * if {@code length} is greater than {@code dst.writableBytes}
* if {@code dst.writerIndex + length} is greater than
* {@code dst.capacity}
*/ */
void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int length);
@ -909,8 +934,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if the specified {@code dstIndex} is less than {@code 0}, * if the specified {@code dstIndex} is less than {@code 0},
* if {@code this.readerIndex + length} is greater than * if {@code length} is greater than {@code this.readableBytes}, or
* {@code this.writerIndex}, or
* if {@code dstIndex + length} is greater than * if {@code dstIndex + length} is greater than
* {@code dst.capacity} * {@code dst.capacity}
*/ */
@ -922,10 +946,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* by the number of the transferred bytes (= {@code dst.length}). * by the number of the transferred bytes (= {@code dst.length}).
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + dst.length} is greater than * if {@code dst.length} is greater than {@code this.readableBytes}
* {@code this.writerIndex} or
* if {@code this.readableBytes} is greater than
* {@code dst.length}
*/ */
void readBytes(byte[] dst); void readBytes(byte[] dst);
@ -939,8 +960,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if the specified {@code dstIndex} is less than {@code 0}, * if the specified {@code dstIndex} is less than {@code 0},
* if {@code this.readerIndex + length} is greater than * if {@code length} is greater than {@code this.readableBytes}, or
* {@code this.writerIndex}, or
* if {@code dstIndex + length} is greater than {@code dst.length} * if {@code dstIndex + length} is greater than {@code dst.length}
*/ */
void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst, int dstIndex, int length);
@ -952,11 +972,8 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* number of the transferred bytes. * number of the transferred bytes.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + dst.remaining()} is greater than * if {@code dst.remaining()} is greater than
* {@code this.capacity} or * {@code this.readableBytes}
* if {@code this.readableBytes} is greater than
* {@code dst.remaining}
*
*/ */
void readBytes(ByteBuffer dst); void readBytes(ByteBuffer dst);
@ -967,8 +984,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* @param length the number of bytes to transfer * @param length the number of bytes to transfer
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + length} is greater than * if {@code length} is greater than {@code this.readableBytes}
* {@code this.capacity}
* @throws IOException * @throws IOException
* if the specified stream threw an exception during I/O * if the specified stream threw an exception during I/O
*/ */
@ -983,8 +999,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* @return the actual number of bytes written out to the specified channel * @return the actual number of bytes written out to the specified channel
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + length} is greater than * if {@code length} is greater than {@code this.readableBytes}
* {@code this.capacity}
* @throws IOException * @throws IOException
* if the specified channel threw an exception during I/O * if the specified channel threw an exception during I/O
*/ */
@ -995,8 +1010,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* {@code length} in this buffer. * {@code length} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.readerIndex + length} is greater than * if {@code length} is greater than {@code this.readableBytes}
* {@code this.writerIndex}
*/ */
void skipBytes(int length); void skipBytes(int length);
@ -1016,8 +1030,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* and increases the {@code writerIndex} by {@code 1} in this buffer. * and increases the {@code writerIndex} by {@code 1} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + 1} is greater than * if {@code this.writableBytes} is less than {@code 1}
* {@code this.capacity}
*/ */
void writeByte(byte value); void writeByte(byte value);
@ -1027,8 +1040,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* in this buffer. * in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + 2} is greater than * if {@code this.writableBytes} is less than {@code 2}
* {@code this.capacity}
*/ */
void writeShort(short value); void writeShort(short value);
@ -1038,8 +1050,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* in this buffer. * in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + 3} is greater than * if {@code this.writableBytes} is less than {@code 3}
* {@code this.capacity}
*/ */
void writeMedium(int value); void writeMedium(int value);
@ -1048,8 +1059,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* and increases the {@code writerIndex} by {@code 4} in this buffer. * and increases the {@code writerIndex} by {@code 4} in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + 4} is greater than * if {@code this.writableBytes} is less than {@code 4}
* {@code this.capacity}
*/ */
void writeInt(int value); void writeInt(int value);
@ -1059,8 +1069,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* in this buffer. * in this buffer.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + 8} is greater than * if {@code this.writableBytes} is less than {@code 8}
* {@code this.capacity}
*/ */
void writeLong(long value); void writeLong(long value);
@ -1075,8 +1084,9 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* doesn't. * doesn't.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + src.readableBytes} is greater than * if {@code src.readableBytes} is greater than
* {@code this.capacity} * {@code this.writableBytes}
*
*/ */
void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src);
@ -1092,8 +1102,8 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* @param length the number of bytes to transfer * @param length the number of bytes to transfer
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + length} is greater than * if {@code length} is greater than {@code this.writableBytes} or
* {@code this.capacity} * if {@code length} is greater then {@code src.readableBytes}
*/ */
void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int length);
@ -1109,8 +1119,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* if the specified {@code srcIndex} is less than {@code 0}, * if the specified {@code srcIndex} is less than {@code 0},
* if {@code srcIndex + length} is greater than * if {@code srcIndex + length} is greater than
* {@code src.capacity}, or * {@code src.capacity}, or
* if {@code this.writerIndex + length} is greater than * if {@code length} is greater than {@code this.writableBytes}
* {@code this.capacity}
*/ */
void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length);
@ -1120,8 +1129,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* by the number of the transferred bytes (= {@code src.length}). * by the number of the transferred bytes (= {@code src.length}).
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + src.length} is greater than * if {@code src.length} is greater than {@code this.writableBytes}
* {@code this.capacity}
*/ */
void writeBytes(byte[] src); void writeBytes(byte[] src);
@ -1137,8 +1145,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* if the specified {@code srcIndex} is less than {@code 0}, * if the specified {@code srcIndex} is less than {@code 0},
* if {@code srcIndex + length} is greater than * if {@code srcIndex + length} is greater than
* {@code src.length}, or * {@code src.length}, or
* if {@code this.writerIndex + length} is greater than * if {@code length} is greater than {@code this.writableBytes}
* {@code this.capacity}
*/ */
void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src, int srcIndex, int length);
@ -1149,8 +1156,8 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* number of the transferred bytes. * number of the transferred bytes.
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + src.remaining()} is greater than * if {@code src.remaining()} is greater than
* {@code this.capacity} * {@code this.writableBytes}
*/ */
void writeBytes(ByteBuffer src); void writeBytes(ByteBuffer src);
@ -1162,8 +1169,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* @param length the number of bytes to transfer * @param length the number of bytes to transfer
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + length} is greater than * if {@code length} is greater than {@code this.writableBytes}
* {@code this.capacity}
* @throws IOException * @throws IOException
* if the specified stream threw an exception during I/O * if the specified stream threw an exception during I/O
*/ */
@ -1179,8 +1185,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* @return the actual number of bytes read in from the specified channel * @return the actual number of bytes read in from the specified channel
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + length} is greater than * if {@code length} is greater than {@code this.writableBytes}
* {@code this.capacity}
* @throws IOException * @throws IOException
* if the specified channel threw an exception during I/O * if the specified channel threw an exception during I/O
*/ */
@ -1194,8 +1199,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* @param length the number of <tt>NUL</tt>s to write to the buffer * @param length the number of <tt>NUL</tt>s to write to the buffer
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if {@code this.writerIndex + length} is greater than * if {@code length} is greater than {@code this.writableBytes}
* {@code this.capacity}
*/ */
void writeZero(int length); void writeZero(int length);

View File

@ -109,8 +109,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
} }
public void getBytes(int index, ByteBuffer dst) { public void getBytes(int index, ByteBuffer dst) {
checkIndex(index, dst.remaining()); reject();
buffer.getBytes(index, dst);
} }
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) { public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
@ -118,9 +117,12 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
buffer.getBytes(index, dst, dstIndex, length); buffer.getBytes(index, dst, dstIndex, length);
} }
public void getBytes(int index, ChannelBuffer dst, int length) {
reject();
}
public void getBytes(int index, ChannelBuffer dst) { public void getBytes(int index, ChannelBuffer dst) {
checkIndex(index, dst.writableBytes()); reject();
buffer.getBytes(index, dst);
} }
public int getBytes(int index, GatheringByteChannel out, int length) public int getBytes(int index, GatheringByteChannel out, int length)
@ -233,8 +235,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
} }
public void readBytes(ByteBuffer dst) { public void readBytes(ByteBuffer dst) {
checkReadableBytes(dst.remaining()); reject();
buffer.readBytes(dst);
} }
public void readBytes(ChannelBuffer dst, int dstIndex, int length) { public void readBytes(ChannelBuffer dst, int dstIndex, int length) {
@ -243,13 +244,11 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
} }
public void readBytes(ChannelBuffer dst, int length) { public void readBytes(ChannelBuffer dst, int length) {
checkReadableBytes(length); reject();
buffer.readBytes(dst, length);
} }
public void readBytes(ChannelBuffer dst) { public void readBytes(ChannelBuffer dst) {
checkReadableBytes(dst.writableBytes()); reject();
buffer.readBytes(dst);
} }
public ChannelBuffer readBytes(ChannelBufferIndexFinder endIndexFinder) { public ChannelBuffer readBytes(ChannelBufferIndexFinder endIndexFinder) {
@ -360,6 +359,10 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
reject(); reject();
} }
public void setBytes(int index, ChannelBuffer src, int length) {
reject();
}
public void setBytes(int index, ChannelBuffer src) { public void setBytes(int index, ChannelBuffer src) {
reject(); reject();
} }