Package org.jboss.netty.buffer
Class EmptyChannelBuffer
java.lang.Object
org.jboss.netty.buffer.AbstractChannelBuffer
org.jboss.netty.buffer.HeapChannelBuffer
org.jboss.netty.buffer.BigEndianHeapChannelBuffer
org.jboss.netty.buffer.EmptyChannelBuffer
- All Implemented Interfaces:
Comparable<ChannelBuffer>,ChannelBuffer
An immutable empty buffer implementation. Typically used as a singleton via
ChannelBuffers.EMPTY_BUFFER and returned by ChannelBuffers.buffer(int) etc when
an empty buffer is requested.
Note: For backwards compatibility, this class extends BigEndianHeapChannelBuffer.
However, it never makes any writes to the reader and writer indices, which avoids contention
when the singleton instance is used concurrently.
-
Field Summary
FieldsFields inherited from class org.jboss.netty.buffer.HeapChannelBuffer
array -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckReadableBytes(int length) Throws anIndexOutOfBoundsExceptionthe length is not 0.private voidcheckWritableBytes(int length) Throws anIndexOutOfBoundsExceptionthe length is not 0.voidclear()Sets thereaderIndexandwriterIndexof this buffer to0.voidDiscards the bytes between the 0th index andreaderIndex.voidMarks the currentreaderIndexin this buffer.voidMarks the currentwriterIndexin this buffer.voidreadBytes(byte[] dst) Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=dst.length).voidreadBytes(byte[] dst, int dstIndex, int length) Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).readBytes(int length) Transfers this buffer's data to a newly created buffer starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).voidreadBytes(OutputStream out, int length) Transfers this buffer's data to the specified stream starting at the currentreaderIndex.voidreadBytes(ByteBuffer dst) Transfers this buffer's data to the specified destination starting at the currentreaderIndexuntil the destination's position reaches its limit, and increases thereaderIndexby the number of the transferred bytes.intreadBytes(GatheringByteChannel out, int length) Transfers this buffer's data to the specified stream starting at the currentreaderIndex.voidreadBytes(ChannelBuffer dst) Transfers this buffer's data to the specified destination starting at the currentreaderIndexuntil the destination becomes non-writable, and increases thereaderIndexby the number of the transferred bytes.voidreadBytes(ChannelBuffer dst, int length) Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).voidreadBytes(ChannelBuffer dst, int dstIndex, int length) Transfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).voidreaderIndex(int readerIndex) Sets thereaderIndexof this buffer.readSlice(int length) Returns a new slice of this buffer's sub-region starting at the currentreaderIndexand increases thereaderIndexby the size of the new slice (=length).voidRepositions the currentreaderIndexto the markedreaderIndexin this buffer.voidRepositions the currentwriterIndexto the markedwriterIndexin this buffer.voidsetIndex(int readerIndex, int writerIndex) Sets thereaderIndexandwriterIndexof this buffer in one shot.voidskipBytes(int length) Increases the currentreaderIndexby the specifiedlengthin this buffer.voidwriteBytes(byte[] src, int srcIndex, int length) Transfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).intwriteBytes(InputStream in, int length) Transfers the content of the specified stream to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes.voidwriteBytes(ByteBuffer src) Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexuntil the source buffer's position reaches its limit, and increases thewriterIndexby the number of the transferred bytes.intwriteBytes(ScatteringByteChannel in, int length) Transfers the content of the specified channel to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes.voidwriteBytes(ChannelBuffer src, int length) Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).voidwriteBytes(ChannelBuffer src, int srcIndex, int length) Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).voidwriterIndex(int writerIndex) Sets thewriterIndexof this buffer.voidwriteZero(int length) Fills this buffer with NUL (0x00) starting at the currentwriterIndexand increases thewriterIndexby the specifiedlength.Methods inherited from class org.jboss.netty.buffer.BigEndianHeapChannelBuffer
copy, duplicate, factory, getInt, getLong, getShort, getUnsignedMedium, order, setInt, setLong, setMedium, setShortMethods inherited from class org.jboss.netty.buffer.HeapChannelBuffer
array, arrayOffset, capacity, getByte, getBytes, getBytes, getBytes, getBytes, getBytes, hasArray, isDirect, setByte, setBytes, setBytes, setBytes, setBytes, setBytes, slice, toByteBufferMethods inherited from class org.jboss.netty.buffer.AbstractChannelBuffer
bytesBefore, bytesBefore, bytesBefore, bytesBefore, bytesBefore, bytesBefore, compareTo, copy, ensureWritableBytes, equals, getBytes, getBytes, getBytes, getChar, getDouble, getFloat, getMedium, getUnsignedByte, getUnsignedInt, getUnsignedShort, hashCode, indexOf, indexOf, readable, readableBytes, readByte, readChar, readDouble, readerIndex, readFloat, readInt, readLong, readMedium, readShort, readUnsignedByte, readUnsignedInt, readUnsignedMedium, readUnsignedShort, setBytes, setBytes, setBytes, setChar, setDouble, setFloat, setZero, slice, toByteBuffer, toByteBuffers, toByteBuffers, toString, toString, toString, writable, writableBytes, writeByte, writeBytes, writeBytes, writeChar, writeDouble, writeFloat, writeInt, writeLong, writeMedium, writerIndex, writeShort
-
Field Details
-
BUFFER
private static final byte[] BUFFER
-
-
Constructor Details
-
EmptyChannelBuffer
EmptyChannelBuffer()
-
-
Method Details
-
clear
public void clear()Description copied from interface:ChannelBufferSets thereaderIndexandwriterIndexof this buffer to0. This method is identical tosetIndex(0, 0).Please note that the behavior of this method is different from that of NIO buffer, which sets the
limitto thecapacityof the buffer.- Specified by:
clearin interfaceChannelBuffer- Overrides:
clearin classAbstractChannelBuffer
-
readerIndex
public void readerIndex(int readerIndex) Description copied from interface:ChannelBufferSets thereaderIndexof this buffer.- Specified by:
readerIndexin interfaceChannelBuffer- Overrides:
readerIndexin classAbstractChannelBuffer
-
writerIndex
public void writerIndex(int writerIndex) Description copied from interface:ChannelBufferSets thewriterIndexof this buffer.- Specified by:
writerIndexin interfaceChannelBuffer- Overrides:
writerIndexin classAbstractChannelBuffer
-
setIndex
public void setIndex(int readerIndex, int writerIndex) Description copied from interface:ChannelBufferSets thereaderIndexandwriterIndexof this buffer in one shot. This method is useful when you have to worry about the invocation order ofChannelBuffer.readerIndex(int)andChannelBuffer.writerIndex(int)methods. For example, the following code will fail:// Create a buffer whose readerIndex, writerIndex and capacity are // 0, 0 and 8 respectively.
The following code will also fail:ChannelBufferbuf =ChannelBuffers.buffer(8); // IndexOutOfBoundsException is thrown because the specified // readerIndex (2) cannot be greater than the current writerIndex (0). buf.readerIndex(2); buf.writerIndex(4);// Create a buffer whose readerIndex, writerIndex and capacity are // 0, 8 and 8 respectively.
By contrast, this method guarantees that it never throws anChannelBufferbuf =ChannelBuffers.wrappedBuffer(new byte[8]); // readerIndex becomes 8. buf.readLong(); // IndexOutOfBoundsException is thrown because the specified // writerIndex (4) cannot be less than the current readerIndex (8). buf.writerIndex(4); buf.readerIndex(2);IndexOutOfBoundsExceptionas long as the specified indexes meet basic constraints, regardless what the current index values of the buffer are:// No matter what the current state of the buffer is, the following // call always succeeds as long as the capacity of the buffer is not // less than 4. buf.setIndex(2, 4);
- Specified by:
setIndexin interfaceChannelBuffer- Overrides:
setIndexin classAbstractChannelBuffer
-
markReaderIndex
public void markReaderIndex()Description copied from interface:ChannelBufferMarks the currentreaderIndexin this buffer. You can reposition the currentreaderIndexto the markedreaderIndexby callingChannelBuffer.resetReaderIndex(). The initial value of the markedreaderIndexis0.- Specified by:
markReaderIndexin interfaceChannelBuffer- Overrides:
markReaderIndexin classAbstractChannelBuffer
-
resetReaderIndex
public void resetReaderIndex()Description copied from interface:ChannelBufferRepositions the currentreaderIndexto the markedreaderIndexin this buffer.- Specified by:
resetReaderIndexin interfaceChannelBuffer- Overrides:
resetReaderIndexin classAbstractChannelBuffer
-
markWriterIndex
public void markWriterIndex()Description copied from interface:ChannelBufferMarks the currentwriterIndexin this buffer. You can reposition the currentwriterIndexto the markedwriterIndexby callingChannelBuffer.resetWriterIndex(). The initial value of the markedwriterIndexis0.- Specified by:
markWriterIndexin interfaceChannelBuffer- Overrides:
markWriterIndexin classAbstractChannelBuffer
-
resetWriterIndex
public void resetWriterIndex()Description copied from interface:ChannelBufferRepositions the currentwriterIndexto the markedwriterIndexin this buffer.- Specified by:
resetWriterIndexin interfaceChannelBuffer- Overrides:
resetWriterIndexin classAbstractChannelBuffer
-
discardReadBytes
public void discardReadBytes()Description copied from interface:ChannelBufferDiscards the bytes between the 0th index andreaderIndex. It moves the bytes betweenreaderIndexandwriterIndexto the 0th index, and setsreaderIndexandwriterIndexto0andoldWriterIndex - oldReaderIndexrespectively.Please refer to the class documentation for more detailed explanation.
- Specified by:
discardReadBytesin interfaceChannelBuffer- Overrides:
discardReadBytesin classAbstractChannelBuffer
-
readBytes
Description copied from interface:ChannelBufferTransfers this buffer's data to a newly created buffer starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length). The returned buffer'sreaderIndexandwriterIndexare0andlengthrespectively.- Specified by:
readBytesin interfaceChannelBuffer- Overrides:
readBytesin classAbstractChannelBuffer- Parameters:
length- the number of bytes to transfer- Returns:
- the newly created buffer which contains the transferred bytes
-
readSlice
Description copied from interface:ChannelBufferReturns a new slice of this buffer's sub-region starting at the currentreaderIndexand increases thereaderIndexby the size of the new slice (=length).- Specified by:
readSlicein interfaceChannelBuffer- Overrides:
readSlicein classAbstractChannelBuffer- Parameters:
length- the size of the new slice- Returns:
- the newly created slice
-
readBytes
public void readBytes(byte[] dst, int dstIndex, int length) Description copied from interface:ChannelBufferTransfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).- Specified by:
readBytesin interfaceChannelBuffer- Overrides:
readBytesin classAbstractChannelBuffer- Parameters:
dstIndex- the first index of the destinationlength- the number of bytes to transfer
-
readBytes
public void readBytes(byte[] dst) Description copied from interface:ChannelBufferTransfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=dst.length).- Specified by:
readBytesin interfaceChannelBuffer- Overrides:
readBytesin classAbstractChannelBuffer
-
readBytes
Description copied from interface:ChannelBufferTransfers this buffer's data to the specified destination starting at the currentreaderIndexuntil the destination becomes non-writable, and increases thereaderIndexby the number of the transferred bytes. This method is basically same withChannelBuffer.readBytes(ChannelBuffer, int, int), except that this method increases thewriterIndexof the destination by the number of the transferred bytes whileChannelBuffer.readBytes(ChannelBuffer, int, int)does not.- Specified by:
readBytesin interfaceChannelBuffer- Overrides:
readBytesin classAbstractChannelBuffer
-
readBytes
Description copied from interface:ChannelBufferTransfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length). This method is basically same withChannelBuffer.readBytes(ChannelBuffer, int, int), except that this method increases thewriterIndexof the destination by the number of the transferred bytes (=length) whileChannelBuffer.readBytes(ChannelBuffer, int, int)does not.- Specified by:
readBytesin interfaceChannelBuffer- Overrides:
readBytesin classAbstractChannelBuffer
-
readBytes
Description copied from interface:ChannelBufferTransfers this buffer's data to the specified destination starting at the currentreaderIndexand increases thereaderIndexby the number of the transferred bytes (=length).- Specified by:
readBytesin interfaceChannelBuffer- Overrides:
readBytesin classAbstractChannelBuffer- Parameters:
dstIndex- the first index of the destinationlength- the number of bytes to transfer
-
readBytes
Description copied from interface:ChannelBufferTransfers this buffer's data to the specified destination starting at the currentreaderIndexuntil the destination's position reaches its limit, and increases thereaderIndexby the number of the transferred bytes.- Specified by:
readBytesin interfaceChannelBuffer- Overrides:
readBytesin classAbstractChannelBuffer
-
readBytes
Description copied from interface:ChannelBufferTransfers this buffer's data to the specified stream starting at the currentreaderIndex.- Specified by:
readBytesin interfaceChannelBuffer- Overrides:
readBytesin classAbstractChannelBuffer- Parameters:
length- the maximum number of bytes to transfer- Returns:
- the actual number of bytes written out to the specified channel
- Throws:
IOException- if the specified channel threw an exception during I/O
-
readBytes
Description copied from interface:ChannelBufferTransfers this buffer's data to the specified stream starting at the currentreaderIndex.- Specified by:
readBytesin interfaceChannelBuffer- Overrides:
readBytesin classAbstractChannelBuffer- Parameters:
length- the number of bytes to transfer- Throws:
IOException- if the specified stream threw an exception during I/O
-
skipBytes
public void skipBytes(int length) Description copied from interface:ChannelBufferIncreases the currentreaderIndexby the specifiedlengthin this buffer.- Specified by:
skipBytesin interfaceChannelBuffer- Overrides:
skipBytesin classAbstractChannelBuffer
-
writeBytes
public void writeBytes(byte[] src, int srcIndex, int length) Description copied from interface:ChannelBufferTransfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).- Specified by:
writeBytesin interfaceChannelBuffer- Overrides:
writeBytesin classAbstractChannelBuffer- Parameters:
srcIndex- the first index of the sourcelength- the number of bytes to transfer
-
writeBytes
Description copied from interface:ChannelBufferTransfers the specified source buffer's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length). This method is basically same withChannelBuffer.writeBytes(ChannelBuffer, int, int), except that this method increases thereaderIndexof the source buffer by the number of the transferred bytes (=length) whileChannelBuffer.writeBytes(ChannelBuffer, int, int)does not.- Specified by:
writeBytesin interfaceChannelBuffer- Overrides:
writeBytesin classAbstractChannelBuffer- Parameters:
length- the number of bytes to transfer
-
writeBytes
Description copied from interface:ChannelBufferTransfers the specified source buffer's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).- Specified by:
writeBytesin interfaceChannelBuffer- Overrides:
writeBytesin classAbstractChannelBuffer- Parameters:
srcIndex- the first index of the sourcelength- the number of bytes to transfer
-
writeBytes
Description copied from interface:ChannelBufferTransfers the specified source buffer's data to this buffer starting at the currentwriterIndexuntil the source buffer's position reaches its limit, and increases thewriterIndexby the number of the transferred bytes.- Specified by:
writeBytesin interfaceChannelBuffer- Overrides:
writeBytesin classAbstractChannelBuffer
-
writeBytes
Description copied from interface:ChannelBufferTransfers the content of the specified stream to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes.- Specified by:
writeBytesin interfaceChannelBuffer- Overrides:
writeBytesin classAbstractChannelBuffer- Parameters:
length- the number of bytes to transfer- Returns:
- the actual number of bytes read in from the specified stream
- Throws:
IOException- if the specified stream threw an exception during I/O
-
writeBytes
Description copied from interface:ChannelBufferTransfers the content of the specified channel to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes.- Specified by:
writeBytesin interfaceChannelBuffer- Overrides:
writeBytesin classAbstractChannelBuffer- Parameters:
length- the maximum number of bytes to transfer- Returns:
- the actual number of bytes read in from the specified channel
- Throws:
IOException- if the specified channel threw an exception during I/O
-
writeZero
public void writeZero(int length) Description copied from interface:ChannelBufferFills this buffer with NUL (0x00) starting at the currentwriterIndexand increases thewriterIndexby the specifiedlength.- Specified by:
writeZeroin interfaceChannelBuffer- Overrides:
writeZeroin classAbstractChannelBuffer- Parameters:
length- the number of NULs to write to the buffer
-
checkWritableBytes
private void checkWritableBytes(int length) Throws anIndexOutOfBoundsExceptionthe length is not 0. -
checkReadableBytes
protected void checkReadableBytes(int length) Throws anIndexOutOfBoundsExceptionthe length is not 0.- Overrides:
checkReadableBytesin classAbstractChannelBuffer
-