|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.netty.buffer.ChannelBuffers
public class ChannelBuffers
Creates a new ChannelBuffer
by allocating new space or by wrapping
or copying existing byte arrays, byte buffers and a string.
import static org.jboss.netty.buffer.ChannelBuffers.*; ChannelBuffer heapBuffer = buffer(128); ChannelBuffer directBuffer = directBuffer(256); ChannelBuffer dynamicBuffer = dynamicBuffer(512); ChannelBuffer wrappedBuffer = wrappedBuffer(new byte[128], new byte[256]); ChannelBuffer copiedBuffer = copiedBuffer(ByteBuffer.allocate(128));
buffer(int)
allocates a new fixed-capacity heap buffer.directBuffer(int)
allocates a new fixed-capacity direct buffer.dynamicBuffer(int)
allocates a new dynamic-capacity heap
buffer, whose capacity increases automatically as needed by a write
operation.wrappedBuffer()
.
You might want to take a look at this method closely if you want to create
a buffer which is composed of more than one array to reduce the number of
memory copy.
copiedBuffer()
. It is also convenient
to use this operation to merge multiple buffers into one buffer.
Field Summary | |
---|---|
static ByteOrder |
BIG_ENDIAN
Big endian byte order. |
static ChannelBuffer |
EMPTY_BUFFER
A buffer whose capacity is 0 . |
static ByteOrder |
LITTLE_ENDIAN
Little endian byte order. |
Method Summary | |
---|---|
static ChannelBuffer |
buffer(ByteOrder endianness,
int capacity)
Creates a new Java heap buffer with the specified endianness
and capacity . |
static ChannelBuffer |
buffer(int capacity)
Creates a new big-endian Java heap buffer with the specified capacity . |
static int |
compare(ChannelBuffer bufferA,
ChannelBuffer bufferB)
Compares the two specified buffers as described in ChannelBuffer.compareTo(ChannelBuffer) . |
static ChannelBuffer |
copiedBuffer(byte[]... arrays)
Creates a new big-endian buffer whose content is a merged copy of the specified arrays . |
static ChannelBuffer |
copiedBuffer(byte[] array)
Creates a new big-endian buffer whose content is a copy of the specified array . |
static ChannelBuffer |
copiedBuffer(byte[] array,
int offset,
int length)
Creates a new big-endian buffer whose content is a copy of the specified array 's sub-region. |
static ChannelBuffer |
copiedBuffer(ByteBuffer... buffers)
Creates a new buffer whose content is a merged copy of the specified buffers ' slices. |
static ChannelBuffer |
copiedBuffer(ByteBuffer buffer)
Creates a new buffer whose content is a copy of the specified buffer 's current slice. |
static ChannelBuffer |
copiedBuffer(ByteOrder endianness,
byte[]... arrays)
Creates a new buffer with the specified endianness whose
content is a merged copy of the specified arrays . |
static ChannelBuffer |
copiedBuffer(ByteOrder endianness,
byte[] array)
Creates a new buffer with the specified endianness whose
content is a copy of the specified array . |
static ChannelBuffer |
copiedBuffer(ByteOrder endianness,
byte[] array,
int offset,
int length)
Creates a new buffer with the specified endianness whose
content is a copy of the specified array 's sub-region. |
static ChannelBuffer |
copiedBuffer(ByteOrder endianness,
String string,
String charsetName)
Creates a new buffer with the specified endianness whose
content is the specified string encoded by the specified
charsetName . |
static ChannelBuffer |
copiedBuffer(ChannelBuffer... buffers)
Creates a new buffer whose content is a merged copy of the specified buffers ' readable bytes. |
static ChannelBuffer |
copiedBuffer(ChannelBuffer buffer)
Creates a new buffer whose content is a copy of the specified buffer 's readable bytes. |
static ChannelBuffer |
copiedBuffer(String string,
String charsetName)
Creates a new big-endian buffer whose content is the specified string encoded by the specified charsetName . |
static ChannelBuffer |
directBuffer(ByteOrder endianness,
int capacity)
Creates a new direct buffer with the specified endianness and
capacity . |
static ChannelBuffer |
directBuffer(int capacity)
Creates a new big-endian direct buffer with the specified capacity . |
static ChannelBuffer |
dynamicBuffer()
Creates a new big-endian dynamic buffer whose estimated data length is 256 bytes. |
static ChannelBuffer |
dynamicBuffer(ByteOrder endianness,
int estimatedLength)
Creates a new dynamic buffer with the specified endianness and the specified estimated data length. |
static ChannelBuffer |
dynamicBuffer(int estimatedLength)
Creates a new big-endian dynamic buffer with the specified estimated data length. |
static boolean |
equals(ChannelBuffer bufferA,
ChannelBuffer bufferB)
Returns true if and only if the two specified buffers are
identical to each other as described in ChannelBuffer#equals(Object) . |
static int |
hashCode(ChannelBuffer buffer)
Calculates the hash code of the specified buffer. |
static String |
hexDump(ChannelBuffer buffer)
Returns a hex dump of the specified buffer's readable bytes. |
static String |
hexDump(ChannelBuffer buffer,
int fromIndex,
int length)
Returns a hex dump of the specified buffer's sub-region. |
static int |
indexOf(ChannelBuffer buffer,
int fromIndex,
int toIndex,
byte value)
The default implementation of ChannelBuffer.indexOf(int, int, byte) . |
static int |
indexOf(ChannelBuffer buffer,
int fromIndex,
int toIndex,
ChannelBufferIndexFinder indexFinder)
The default implementation of ChannelBuffer.indexOf(int, int, ChannelBufferIndexFinder) . |
static int |
swapInt(int value)
Toggles the endianness of the specified 32-bit integer. |
static long |
swapLong(long value)
Toggles the endianness of the specified 64-bit long integer. |
static int |
swapMedium(int value)
Toggles the endianness of the specified 24-bit medium integer. |
static short |
swapShort(short value)
Toggles the endianness of the specified 16-bit short integer. |
static ChannelBuffer |
unmodifiableBuffer(ChannelBuffer buffer)
Creates a read-only buffer which disallows any modification operations on the specified buffer . |
static ChannelBuffer |
wrappedBuffer(byte[]... arrays)
Creates a new big-endian composite buffer which wraps the specified arrays without copying them. |
static ChannelBuffer |
wrappedBuffer(byte[] array)
Creates a new big-endian buffer which wraps the specified array . |
static ChannelBuffer |
wrappedBuffer(byte[] array,
int offset,
int length)
Creates a new big-endian buffer which wraps the sub-region of the specified array . |
static ChannelBuffer |
wrappedBuffer(ByteBuffer... buffers)
Creates a new composite buffer which wraps the specified NIO buffers without copying them. |
static ChannelBuffer |
wrappedBuffer(ByteBuffer buffer)
Creates a new buffer which wraps the specified NIO buffer's current slice. |
static ChannelBuffer |
wrappedBuffer(ByteOrder endianness,
byte[]... arrays)
Creates a new composite buffer which wraps the specified arrays without copying them. |
static ChannelBuffer |
wrappedBuffer(ByteOrder endianness,
byte[] array)
Creates a new buffer which wraps the specified array with the
specified endianness . |
static ChannelBuffer |
wrappedBuffer(ByteOrder endianness,
byte[] array,
int offset,
int length)
Creates a new buffer which wraps the sub-region of the specified array with the specified endianness . |
static ChannelBuffer |
wrappedBuffer(ChannelBuffer... buffers)
Creates a new composite buffer which wraps the specified buffers without copying them. |
static ChannelBuffer |
wrappedBuffer(ChannelBuffer buffer)
Creates a new buffer which wraps the specified buffer's readable bytes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final ByteOrder BIG_ENDIAN
public static final ByteOrder LITTLE_ENDIAN
public static final ChannelBuffer EMPTY_BUFFER
0
.
Method Detail |
---|
public static ChannelBuffer buffer(int capacity)
capacity
. The new buffer's readerIndex
and
writerIndex
are 0
.
public static ChannelBuffer buffer(ByteOrder endianness, int capacity)
endianness
and capacity
. The new buffer's readerIndex
and
writerIndex
are 0
.
public static ChannelBuffer directBuffer(int capacity)
capacity
. The new buffer's readerIndex
and
writerIndex
are 0
.
public static ChannelBuffer directBuffer(ByteOrder endianness, int capacity)
endianness
and
capacity
. The new buffer's readerIndex
and
writerIndex
are 0
.
public static ChannelBuffer dynamicBuffer()
256
bytes. The new buffer's readerIndex
and
writerIndex
are 0
.
public static ChannelBuffer dynamicBuffer(int estimatedLength)
readerIndex
and
writerIndex
are 0
.
public static ChannelBuffer dynamicBuffer(ByteOrder endianness, int estimatedLength)
readerIndex
and writerIndex
are 0
.
public static ChannelBuffer wrappedBuffer(byte[] array)
array
.
A modification on the specified array's content will be visible to the
returned buffer.
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[] array)
array
with the
specified endianness
. A modification on the specified array's
content will be visible to the returned buffer.
public static ChannelBuffer wrappedBuffer(byte[] array, int offset, int length)
array
. A modification on the specified array's
content will be visible to the returned buffer.
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[] array, int offset, int length)
array
with the specified endianness
. A modification on
the specified array's content will be visible to the returned buffer.
public static ChannelBuffer wrappedBuffer(ByteBuffer buffer)
public static ChannelBuffer wrappedBuffer(ChannelBuffer buffer)
public static ChannelBuffer wrappedBuffer(byte[]... arrays)
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[]... arrays)
endianness
- the endianness of the new bufferpublic static ChannelBuffer wrappedBuffer(ChannelBuffer... buffers)
IllegalArgumentException
- if the specified buffers' endianness are different from each
otherpublic static ChannelBuffer wrappedBuffer(ByteBuffer... buffers)
IllegalArgumentException
- if the specified buffers' endianness are different from each
otherpublic static ChannelBuffer copiedBuffer(byte[] array)
array
. The new buffer's readerIndex
and
writerIndex
are 0
and array.length
respectively.
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[] array)
endianness
whose
content is a copy of the specified array
. The new buffer's
readerIndex
and writerIndex
are 0
and
array.length
respectively.
public static ChannelBuffer copiedBuffer(byte[] array, int offset, int length)
array
's sub-region. The new buffer's
readerIndex
and writerIndex
are 0
and
the specified length
respectively.
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[] array, int offset, int length)
endianness
whose
content is a copy of the specified array
's sub-region. The new
buffer's readerIndex
and writerIndex
are 0
and
the specified length
respectively.
public static ChannelBuffer copiedBuffer(ByteBuffer buffer)
buffer
's current slice. The new buffer's readerIndex
and writerIndex
are 0
and buffer.remaining
respectively.
public static ChannelBuffer copiedBuffer(ChannelBuffer buffer)
buffer
's readable bytes. The new buffer's readerIndex
and writerIndex
are 0
and buffer.readableBytes
respectively.
public static ChannelBuffer copiedBuffer(byte[]... arrays)
arrays
. The new buffer's readerIndex
and writerIndex
are 0
and the sum of all arrays'
length
respectively.
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[]... arrays)
endianness
whose
content is a merged copy of the specified arrays
. The new
buffer's readerIndex
and writerIndex
are 0
and the sum of all arrays' length
respectively.
public static ChannelBuffer copiedBuffer(ChannelBuffer... buffers)
buffers
' readable bytes. The new buffer's readerIndex
and writerIndex
are 0
and the sum of all buffers'
readableBytes
respectively.
IllegalArgumentException
- if the specified buffers' endianness are different from each
otherpublic static ChannelBuffer copiedBuffer(ByteBuffer... buffers)
buffers
' slices. The new buffer's readerIndex
and
writerIndex
are 0
and the sum of all buffers'
remaining
respectively.
IllegalArgumentException
- if the specified buffers' endianness are different from each
otherpublic static ChannelBuffer copiedBuffer(String string, String charsetName)
string
encoded by the specified charsetName
.
The new buffer's readerIndex
and writerIndex
are
0
and the length of the encoded string respectively.
public static ChannelBuffer copiedBuffer(ByteOrder endianness, String string, String charsetName)
endianness
whose
content is the specified string
encoded by the specified
charsetName
. The new buffer's readerIndex
and
writerIndex
are 0
and the length of the encoded string
respectively.
public static ChannelBuffer unmodifiableBuffer(ChannelBuffer buffer)
buffer
. The new buffer has the same
readerIndex
and writerIndex
with the specified
buffer
.
public static String hexDump(ChannelBuffer buffer)
public static String hexDump(ChannelBuffer buffer, int fromIndex, int length)
public static int hashCode(ChannelBuffer buffer)
public static boolean equals(ChannelBuffer bufferA, ChannelBuffer bufferB)
true
if and only if the two specified buffers are
identical to each other as described in ChannelBuffer#equals(Object)
.
This method is useful when implementing a new buffer type.
public static int compare(ChannelBuffer bufferA, ChannelBuffer bufferB)
ChannelBuffer.compareTo(ChannelBuffer)
.
This method is useful when implementing a new buffer type.
public static int indexOf(ChannelBuffer buffer, int fromIndex, int toIndex, byte value)
ChannelBuffer.indexOf(int, int, byte)
.
This method is useful when implementing a new buffer type.
public static int indexOf(ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder)
ChannelBuffer.indexOf(int, int, ChannelBufferIndexFinder)
.
This method is useful when implementing a new buffer type.
public static short swapShort(short value)
public static int swapMedium(int value)
public static int swapInt(int value)
public static long swapLong(long value)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |