|
XNIO API 2.1.0.CR2 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jboss.xnio.Buffers
public final class Buffers

Buffer utility methods.
| Field Summary | |
|---|---|
static ByteBuffer |
EMPTY_BYTE_BUFFER
The empty byte buffer. |
| Method Summary | ||
|---|---|---|
static
|
clear(T buffer)
Clear a buffer. |
|
static Object |
createDumper(ByteBuffer buffer,
int indent,
int columns)
Create an object that returns the dumped form of the given byte buffer when its toString() method is called. |
|
static Object |
createDumper(CharBuffer buffer,
int indent,
int columns)
Create an object that returns the dumped form of the given character buffer when its toString() method is called. |
|
static Pool<ByteBuffer> |
createHeapByteBufferAllocator(int size)
Create a heap-based buffer allocator. |
|
static void |
dump(ByteBuffer buffer,
Appendable dest,
int indent,
int columns)
Dump a byte buffer to the given target. |
|
static void |
dump(CharBuffer buffer,
Appendable dest,
int indent,
int columns)
Dump a character buffer to the given target. |
|
static ByteBuffer |
fill(ByteBuffer buffer,
int value,
int count)
Fill a buffer with a repeated value. |
|
static CharBuffer |
fill(CharBuffer buffer,
int value,
int count)
Fill a buffer with a repeated value. |
|
static IntBuffer |
fill(IntBuffer buffer,
int value,
int count)
Fill a buffer with a repeated value. |
|
static LongBuffer |
fill(LongBuffer buffer,
long value,
int count)
Fill a buffer with a repeated value. |
|
static ShortBuffer |
fill(ShortBuffer buffer,
int value,
int count)
Fill a buffer with a repeated value. |
|
static
|
flip(T buffer)
Flip a buffer. |
|
static String |
getModifiedUtf8(ByteBuffer src)
Get a modified UTF-8 string from the remainder of the buffer. |
|
static String |
getModifiedUtf8Z(ByteBuffer src)
Get a 0-terminated string from the byte buffer, decoding it using "modified UTF-8" encoding. |
|
static boolean |
hasRemaining(Buffer[] buffers)
Determine whether any of the buffers has remaining data. |
|
static boolean |
hasRemaining(Buffer[] buffers,
int offs,
int len)
Determine whether any of the buffers has remaining data. |
|
static
|
limit(T buffer,
int limit)
Set the buffer limit. |
|
static
|
mark(T buffer)
Set the buffer mark. |
|
static
|
position(T buffer,
int position)
Set the buffer position. |
|
static long |
put(ByteBuffer[] dsts,
int doffs,
int dlen,
ByteBuffer src)
Put as many bytes as possible from src into the byte buffers in a scatter fashion. |
|
static ByteBuffer |
putModifiedUtf8(ByteBuffer dest,
String orig)
Put the string into the byte buffer, encoding it using "modified UTF-8" encoding. |
|
static void |
readAscii(ByteBuffer src,
StringBuilder builder)
Read the remainder of a buffer as ASCII text, appending the results to the given string builder. |
|
static void |
readAscii(ByteBuffer src,
StringBuilder builder,
char replacement)
Read the remainder of a buffer as ASCII text, appending the results to the given string builder. |
|
static void |
readAscii(ByteBuffer src,
StringBuilder builder,
int limit,
char replacement)
Read the remainder of a buffer as ASCII text, up to a certain limit, appending the results to the given string builder. |
|
static boolean |
readAsciiLine(ByteBuffer src,
StringBuilder builder)
Read a single line of ASCII text from a byte buffer, appending the results to the given string builder. |
|
static boolean |
readAsciiLine(ByteBuffer src,
StringBuilder builder,
char replacement)
Read a single line of ASCII text from a byte buffer, appending the results to the given string builder. |
|
static boolean |
readAsciiLine(ByteBuffer src,
StringBuilder builder,
char replacement,
char delimiter)
Read a single line of ASCII text from a byte buffer, appending the results to the given string builder, using the given delimiter character instead of EOL. |
|
static boolean |
readAsciiZ(ByteBuffer src,
StringBuilder builder)
Read an ASCIIZ ( NUL-terminated) string from a byte buffer, appending the results to the given string
builder. |
|
static boolean |
readAsciiZ(ByteBuffer src,
StringBuilder builder,
char replacement)
Read an ASCIIZ ( NUL-terminated) string from a byte buffer, appending the results to the given string
builder. |
|
static void |
readLatin1(ByteBuffer src,
StringBuilder builder)
Read the remainder of a buffer as ASCII text, appending the results to the given string builder. |
|
static boolean |
readLatin1Line(ByteBuffer src,
StringBuilder builder)
Read a single line of Latin-1 text from a byte buffer, appending the results to the given string builder. |
|
static boolean |
readLatin1Line(ByteBuffer src,
StringBuilder builder,
char delimiter)
Read a single line of Latin-1 text from a byte buffer, appending the results to the given string builder. |
|
static boolean |
readLatin1Z(ByteBuffer src,
StringBuilder builder)
Read a NUL-terminated Latin-1 string from a byte buffer, appending the results to the given string
builder. |
|
static boolean |
readLine(ByteBuffer src,
StringBuilder builder,
CharsetDecoder decoder)
Read a single line of text from a byte buffer, appending the results to the given string builder. |
|
static boolean |
readLine(ByteBuffer src,
StringBuilder builder,
CharsetDecoder decoder,
char delimiter)
Read a single line of text from a byte buffer, appending the results to the given string builder. |
|
static boolean |
readModifiedUtf8Line(ByteBuffer src,
StringBuilder builder)
Read a single line of modified UTF-8 text from a byte buffer, appending the results to the given string
builder. |
|
static boolean |
readModifiedUtf8Line(ByteBuffer src,
StringBuilder builder,
char replacement)
Read a single line of modified UTF-8 text from a byte buffer, appending the results to the given string
builder. |
|
static boolean |
readModifiedUtf8Line(ByteBuffer src,
StringBuilder builder,
char replacement,
char delimiter)
Read a single line of modified UTF-8 text from a byte buffer, appending the results to the given string
builder. |
|
static boolean |
readModifiedUtf8Z(ByteBuffer src,
StringBuilder builder)
Read a NUL-terminated modified UTF-8 string from a byte buffer, appending the results to the given string
builder. |
|
static boolean |
readModifiedUtf8Z(ByteBuffer src,
StringBuilder builder,
char replacement)
Read a NUL-terminated modified UTF-8 string from a byte buffer, appending the results to the given string
builder. |
|
static long |
remaining(Buffer[] buffers)
Get the total remaining size of all the given buffers. |
|
static long |
remaining(Buffer[] buffers,
int offs,
int len)
Get the total remaining size of all the given buffers. |
|
static
|
reset(T buffer)
Reset the buffer. |
|
static
|
rewind(T buffer)
Rewind the buffer. |
|
static
|
skip(T buffer,
int cnt)
Advance a buffer's position relative to its current position. |
|
static ByteBuffer |
slice(ByteBuffer buffer,
int sliceSize)
Slice the buffer. |
|
static CharBuffer |
slice(CharBuffer buffer,
int sliceSize)
Slice the buffer. |
|
static IntBuffer |
slice(IntBuffer buffer,
int sliceSize)
Slice the buffer. |
|
static LongBuffer |
slice(LongBuffer buffer,
int sliceSize)
Slice the buffer. |
|
static ShortBuffer |
slice(ShortBuffer buffer,
int sliceSize)
Slice the buffer. |
|
static byte[] |
take(ByteBuffer buffer,
int cnt)
Take a certain number of bytes from the buffer and return them in an array. |
|
static char[] |
take(CharBuffer buffer,
int cnt)
Take a certain number of chars from the buffer and return them in an array. |
|
static int[] |
take(IntBuffer buffer,
int cnt)
Take a certain number of ints from the buffer and return them in an array. |
|
static long[] |
take(LongBuffer buffer,
int cnt)
Take a certain number of longs from the buffer and return them in an array. |
|
static short[] |
take(ShortBuffer buffer,
int cnt)
Take a certain number of shorts from the buffer and return them in an array. |
|
static
|
unget(T buffer,
int cnt)
Rewind a buffer's position relative to its current position. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final ByteBuffer EMPTY_BYTE_BUFFER
| Method Detail |
|---|
public static <T extends Buffer> T flip(T buffer)
T - the buffer typebuffer - the buffer to flip
Buffer.flip()public static <T extends Buffer> T clear(T buffer)
T - the buffer typebuffer - the buffer to clear
Buffer.clear()
public static <T extends Buffer> T limit(T buffer,
int limit)
T - the buffer typebuffer - the buffer to setlimit - the new limit
Buffer.limit(int)public static <T extends Buffer> T mark(T buffer)
T - the buffer typebuffer - the buffer to mark
Buffer.mark()
public static <T extends Buffer> T position(T buffer,
int position)
T - the buffer typebuffer - the buffer to setposition - the new position
Buffer.position(int)public static <T extends Buffer> T reset(T buffer)
T - the buffer typebuffer - the buffer to reset
Buffer.reset()public static <T extends Buffer> T rewind(T buffer)
T - the buffer typebuffer - the buffer to rewind
Buffer.rewind()
public static ByteBuffer slice(ByteBuffer buffer,
int sliceSize)
buffer - the buffer to slicesliceSize - the size of the slice
ByteBuffer.slice()
public static ByteBuffer fill(ByteBuffer buffer,
int value,
int count)
buffer - the buffer to fillvalue - the value to fillcount - the number of bytes to fill
public static CharBuffer slice(CharBuffer buffer,
int sliceSize)
buffer - the buffer to slicesliceSize - the size of the slice
CharBuffer.slice()
public static CharBuffer fill(CharBuffer buffer,
int value,
int count)
buffer - the buffer to fillvalue - the value to fillcount - the number of chars to fill
public static ShortBuffer slice(ShortBuffer buffer,
int sliceSize)
buffer - the buffer to slicesliceSize - the size of the slice
ShortBuffer.slice()
public static ShortBuffer fill(ShortBuffer buffer,
int value,
int count)
buffer - the buffer to fillvalue - the value to fillcount - the number of shorts to fill
public static IntBuffer slice(IntBuffer buffer,
int sliceSize)
buffer - the buffer to slicesliceSize - the size of the slice
IntBuffer.slice()
public static IntBuffer fill(IntBuffer buffer,
int value,
int count)
buffer - the buffer to fillvalue - the value to fillcount - the number of ints to fill
public static LongBuffer slice(LongBuffer buffer,
int sliceSize)
buffer - the buffer to slicesliceSize - the size of the slice
LongBuffer.slice()
public static LongBuffer fill(LongBuffer buffer,
long value,
int count)
buffer - the buffer to fillvalue - the value to fillcount - the number of longs to fill
public static <T extends Buffer> T skip(T buffer,
int cnt)
T - the buffer typebuffer - the buffer to setcnt - the distantce to skip
Buffer.position(int)
public static <T extends Buffer> T unget(T buffer,
int cnt)
T - the buffer typebuffer - the buffer to setcnt - the distantce to skip backwards
Buffer.position(int)
public static byte[] take(ByteBuffer buffer,
int cnt)
buffer - the buffer to readcnt - the number of bytes to take
public static char[] take(CharBuffer buffer,
int cnt)
buffer - the buffer to readcnt - the number of chars to take
public static short[] take(ShortBuffer buffer,
int cnt)
buffer - the buffer to readcnt - the number of shorts to take
public static int[] take(IntBuffer buffer,
int cnt)
buffer - the buffer to readcnt - the number of ints to take
public static long[] take(LongBuffer buffer,
int cnt)
buffer - the buffer to readcnt - the number of longs to take
public static Object createDumper(ByteBuffer buffer,
int indent,
int columns)
toString() method is called.
Useful for logging byte buffers; if the toString() method is never called, the process of dumping the
buffer is never performed.
buffer - the bufferindent - the indentation to usecolumns - the number of 8-byte columns
public static void dump(ByteBuffer buffer,
Appendable dest,
int indent,
int columns)
throws IOException
buffer - the bufferdest - the targetindent - the indentation to usecolumns - the number of 8-byte columns
IOException - if an error occurs during append
public static Object createDumper(CharBuffer buffer,
int indent,
int columns)
toString() method is called.
Useful for logging character buffers; if the toString() method is never called, the process of dumping the
buffer is never performed.
buffer - the bufferindent - the indentation to usecolumns - the number of 8-byte columns
public static void dump(CharBuffer buffer,
Appendable dest,
int indent,
int columns)
throws IOException
buffer - the bufferdest - the targetindent - the indentation to usecolumns - the number of 8-byte columns
IOException - if an error occurs during appendpublic static Pool<ByteBuffer> createHeapByteBufferAllocator(int size)
size - the size of the returned buffers
public static boolean hasRemaining(Buffer[] buffers,
int offs,
int len)
buffers - the buffersoffs - the offset into the buffers arraylen - the number of buffers to check
true if any of the selected buffers has remaining datapublic static boolean hasRemaining(Buffer[] buffers)
buffers - the buffers
true if any of the selected buffers has remaining data
public static long remaining(Buffer[] buffers,
int offs,
int len)
buffers - the buffersoffs - the offset into the buffers arraylen - the number of buffers to check
public static long remaining(Buffer[] buffers)
buffers - the buffers
public static long put(ByteBuffer[] dsts,
int doffs,
int dlen,
ByteBuffer src)
src into the byte buffers in a scatter fashion.
dsts - the destination buffersdoffs - the offset into the destination buffers arraydlen - the number of buffers to updatesrc - the source buffer
public static ByteBuffer putModifiedUtf8(ByteBuffer dest,
String orig)
throws BufferOverflowException
dest - the byte bufferorig - the source bytes
BufferOverflowException - if there is not enough space in the buffer for the complete stringDataOutput.writeUTF(String)
public static String getModifiedUtf8Z(ByteBuffer src)
throws BufferUnderflowException
src - the source buffer
BufferUnderflowException - if the end of the buffer was reached before encountering a 0
public static String getModifiedUtf8(ByteBuffer src)
throws BufferUnderflowException
src - the buffer
BufferUnderflowException - if the buffer ends abruptly in the midst of a single character
public static boolean readAsciiZ(ByteBuffer src,
StringBuilder builder)
NUL-terminated) string from a byte buffer, appending the results to the given string
builder. If no NUL character is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character '?' is written
to the string builder in its place.
src - the source bufferbuilder - the destination builder
true if the entire string was read, false if more data is needed
public static boolean readAsciiZ(ByteBuffer src,
StringBuilder builder,
char replacement)
NUL-terminated) string from a byte buffer, appending the results to the given string
builder. If no NUL character is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character designated by replacement is written
to the string builder in its place.
src - the source bufferbuilder - the destination builderreplacement - the replacement character for invalid bytes
true if the entire string was read, false if more data is needed
public static boolean readAsciiLine(ByteBuffer src,
StringBuilder builder)
EOL character is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character '?' is written
to the string builder in its place. The EOL character will be included in the resultant string.
src - the source bufferbuilder - the destination builder
true if the entire string was read, false if more data is needed
public static boolean readAsciiLine(ByteBuffer src,
StringBuilder builder,
char replacement)
EOL character is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character designated by replacement is written
to the string builder in its place. The EOL character will be included in the resultant string.
src - the source bufferbuilder - the destination builderreplacement - the replacement character for invalid bytes
true if the entire string was read, false if more data is needed
public static boolean readAsciiLine(ByteBuffer src,
StringBuilder builder,
char replacement,
char delimiter)
EOL. If no delimiter character is encountered,
false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character designated by replacement is written
to the string builder in its place. The delimiter character will be included in the resultant string.
src - the source bufferbuilder - the destination builderreplacement - the replacement character for invalid bytesdelimiter - the character which marks the end of the line
true if the entire string was read, false if more data is needed
public static void readAscii(ByteBuffer src,
StringBuilder builder)
'?' is written
to the string builder in its place.
src - the source bufferbuilder - the destination builder
public static void readAscii(ByteBuffer src,
StringBuilder builder,
char replacement)
replacement is written
to the string builder in its place.
src - the source bufferbuilder - the destination builderreplacement - the replacement character for invalid bytes
public static void readAscii(ByteBuffer src,
StringBuilder builder,
int limit,
char replacement)
replacement is written
to the string builder in its place.
src - the source bufferbuilder - the destination builderlimit - the maximum number of characters to writereplacement - the replacement character for invalid bytes
public static boolean readLatin1Z(ByteBuffer src,
StringBuilder builder)
NUL-terminated Latin-1 string from a byte buffer, appending the results to the given string
builder. If no NUL character is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer.
src - the source bufferbuilder - the destination builder
true if the entire string was read, false if more data is needed
public static boolean readLatin1Line(ByteBuffer src,
StringBuilder builder)
EOL character is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. The EOL character will be included in the resultant string.
src - the source bufferbuilder - the destination builder
true if the entire string was read, false if more data is needed
public static boolean readLatin1Line(ByteBuffer src,
StringBuilder builder,
char delimiter)
false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. The delimiter character will be included in the resultant string.
src - the source bufferbuilder - the destination builderdelimiter - the character which marks the end of the line
true if the entire string was read, false if more data is needed
public static void readLatin1(ByteBuffer src,
StringBuilder builder)
src - the source bufferbuilder - the destination builder
public static boolean readModifiedUtf8Z(ByteBuffer src,
StringBuilder builder)
NUL-terminated modified UTF-8 string from a byte buffer, appending the results to the given string
builder. If no NUL byte is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte sequence is read, the character '?' is written
to the string builder in its place.
src - the source bufferbuilder - the destination builder
true if the entire string was read, false if more data is needed
public static boolean readModifiedUtf8Z(ByteBuffer src,
StringBuilder builder,
char replacement)
NUL-terminated modified UTF-8 string from a byte buffer, appending the results to the given string
builder. If no NUL byte is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte sequence is read, the character designated by replacement is written
to the string builder in its place.
src - the source bufferbuilder - the destination builder
true if the entire string was read, false if more data is needed
public static boolean readModifiedUtf8Line(ByteBuffer src,
StringBuilder builder)
modified UTF-8 text from a byte buffer, appending the results to the given string
builder. If no EOL character is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character '?' is written
to the string builder in its place. The EOL character will be included in the resultant string.
src - the source bufferbuilder - the destination builder
true if the entire string was read, false if more data is needed
public static boolean readModifiedUtf8Line(ByteBuffer src,
StringBuilder builder,
char replacement)
modified UTF-8 text from a byte buffer, appending the results to the given string
builder. If no EOL character is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character designated by replacement is written
to the string builder in its place. The EOL character will be included in the resultant string.
src - the source bufferbuilder - the destination builderreplacement - the replacement character for invalid bytes
true if the entire string was read, false if more data is needed
public static boolean readModifiedUtf8Line(ByteBuffer src,
StringBuilder builder,
char replacement,
char delimiter)
modified UTF-8 text from a byte buffer, appending the results to the given string
builder. If no EOL character is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character designated by replacement is written
to the string builder in its place. The delimiter character will be included in the resultant string.
src - the source bufferbuilder - the destination builderreplacement - the replacement character for invalid bytesdelimiter - the character which marks the end of the line
true if the entire string was read, false if more data is needed
public static boolean readLine(ByteBuffer src,
StringBuilder builder,
CharsetDecoder decoder)
EOL character is encountered, false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. Invalid bytes are handled according to the policy specified by the decoder instance.
Since this method decodes only one character at a time, it should not be expected to have the same performance
as the other optimized, character set-specific methods specified in this class.
The EOL character will be included in the resultant string.
src - the source bufferbuilder - the destination builderdecoder - the decoder to use
true if the entire string was read, false if more data is needed
public static boolean readLine(ByteBuffer src,
StringBuilder builder,
CharsetDecoder decoder,
char delimiter)
false is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. Invalid bytes are handled according to the policy specified by the decoder instance.
Since this method decodes only one character at a time, it should not be expected to have the same performance
as the other optimized, character set-specific methods specified in this class. The delimiter character will be
included in the resultant string.
src - the source bufferbuilder - the destination builderdecoder - the decoder to usedelimiter - the character which marks the end of the line
true if the entire string was read, false if more data is needed
|
XNIO API 2.1.0.CR2 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||