public final class Buffers extends Object
Modifier and Type | Field and Description |
---|---|
static ByteBuffer |
EMPTY_BYTE_BUFFER
The empty byte buffer.
|
static Pooled<ByteBuffer> |
EMPTY_POOLED_BYTE_BUFFER
The empty pooled byte buffer.
|
Modifier and Type | Method and Description |
---|---|
static void |
addRandom(ByteBuffer target)
Add a random amount of random data to the target buffer using the thread-local RNG.
|
static void |
addRandom(ByteBuffer target,
int count)
Add
count bytes of random data to the target buffer using the thread-local RNG. |
static void |
addRandom(ByteBuffer target,
Random random)
Add a random amount of random data to the target buffer.
|
static void |
addRandom(ByteBuffer target,
Random random,
int count)
Add
count bytes of random data to the target buffer. |
static <B extends Buffer> |
allocatedBufferPool(BufferAllocator<B> allocator,
int size)
A buffer pool which allocates a new buffer on every allocate request, and discards buffers on free.
|
static void |
assertWritable(Buffer... buffers)
Assert the writability of the given buffers.
|
static void |
assertWritable(Buffer[] buffers,
int offs,
int len)
Assert the writability of the given buffers.
|
static <T extends Buffer> |
clear(T buffer)
Clear a buffer.
|
static int |
copy(ByteBuffer[] destinations,
int offset,
int length,
ByteBuffer source)
Copy as many bytes as possible from
sources into destinations in a "scatter" fashion. |
static long |
copy(ByteBuffer[] destinations,
int destOffset,
int destLength,
ByteBuffer[] sources,
int srcOffset,
int srcLength)
Copy as many bytes as possible from
sources into destinations by a combined "scatter"/"gather" operation. |
static int |
copy(ByteBuffer destination,
ByteBuffer source)
Copy as many bytes as possible from
source into destination . |
static int |
copy(ByteBuffer destination,
ByteBuffer[] sources,
int offset,
int length)
Copy as many bytes as possible from
sources into destination in a "gather" fashion. |
static ByteBuffer |
copy(ByteBuffer buffer,
int sliceSize,
BufferAllocator<ByteBuffer> allocator)
Copy a portion of the buffer into a newly allocated buffer.
|
static int |
copy(int count,
ByteBuffer[] destinations,
int offset,
int length,
ByteBuffer source)
Copy at most
count bytes from sources into destinations in a "scatter" fashion. |
static int |
copy(int count,
ByteBuffer destination,
ByteBuffer source)
Copy at most
count bytes from source into destination . |
static int |
copy(int count,
ByteBuffer destination,
ByteBuffer[] sources,
int offset,
int length)
Copy at most
count bytes from sources into destination in a "gather" fashion. |
static long |
copy(long count,
ByteBuffer[] destinations,
int destOffset,
int destLength,
ByteBuffer[] sources,
int srcOffset,
int srcLength)
Copy at most
count bytes from sources into destinations by a combined "scatter"/"gather" operation. |
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 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 <T extends Buffer> |
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 boolean |
isDirect(Buffer... buffers)
Determine whether the given buffers list is comprised solely of direct buffers or solely of heap buffers.
|
static boolean |
isDirect(Buffer[] buffers,
int offset,
int length)
Determine whether the given buffers list is comprised solely of direct buffers or solely of heap buffers.
|
static boolean |
isSecureBufferPool(Pool<?> pool)
Determine whether the given pool is a secure pool.
|
static <T extends Buffer> |
limit(T buffer,
int limit)
Set the buffer limit.
|
static <T extends Buffer> |
mark(T buffer)
Set the buffer mark.
|
static <B extends Buffer> |
pooledWrapper(B buffer)
Create a pooled wrapper around a buffer.
|
static <T extends Buffer> |
position(T buffer,
int position)
Set the buffer position.
|
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 Latin-1 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 <T extends Buffer> |
reset(T buffer)
Reset the buffer.
|
static <T extends Buffer> |
rewind(T buffer)
Rewind the buffer.
|
static Pool<ByteBuffer> |
secureBufferPool(Pool<ByteBuffer> delegate)
A byte buffer pool which zeroes the content of the buffer before re-pooling it.
|
static <T extends Buffer> |
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 BufferAllocator<ByteBuffer> |
sliceAllocator(ByteBuffer buffer)
A buffer allocator which allocates slices off of the given buffer.
|
static byte[] |
take(ByteBuffer buffer)
Take all of the remaining bytes from the buffer and return them in an array.
|
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)
Take all of the remaining chars 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)
Take all of the remaining ints 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)
Take all of the remaining longs 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)
Take all of the remaining shorts 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 long |
trySkip(Buffer[] buffers,
int offs,
int len,
long cnt)
Attempt to advance a series of buffers' overall position relative to its current position.
|
static int |
trySkip(Buffer buffer,
int cnt)
Attempt to advance a buffer's position relative to its current position.
|
static <T extends Buffer> |
unget(T buffer,
int cnt)
Rewind a buffer's position relative to its current position.
|
static void |
zero(ByteBuffer buffer)
Zero a buffer.
|
static void |
zero(CharBuffer buffer)
Zero a buffer.
|
public static final ByteBuffer EMPTY_BYTE_BUFFER
public static final Pooled<ByteBuffer> EMPTY_POOLED_BYTE_BUFFER
public static <T extends Buffer> T flip(T buffer)
T
- the buffer typebuffer
- the buffer to flipBuffer.flip()
public static <T extends Buffer> T clear(T buffer)
T
- the buffer typebuffer
- the buffer to clearBuffer.clear()
public static <T extends Buffer> T limit(T buffer, int limit)
T
- the buffer typebuffer
- the buffer to setlimit
- the new limitBuffer.limit(int)
public static <T extends Buffer> T mark(T buffer)
T
- the buffer typebuffer
- the buffer to markBuffer.mark()
public static <T extends Buffer> T position(T buffer, int position)
T
- the buffer typebuffer
- the buffer to setposition
- the new positionBuffer.position(int)
public static <T extends Buffer> T reset(T buffer)
T
- the buffer typebuffer
- the buffer to resetBuffer.reset()
public static <T extends Buffer> T rewind(T buffer)
T
- the buffer typebuffer
- the buffer to rewindBuffer.rewind()
public static ByteBuffer slice(ByteBuffer buffer, int sliceSize)
buffer
- the buffer to slicesliceSize
- the size of the sliceByteBuffer.slice()
public static ByteBuffer copy(ByteBuffer buffer, int sliceSize, BufferAllocator<ByteBuffer> allocator)
buffer
- the buffer to slicesliceSize
- the size of the copyallocator
- the buffer allocator to usepublic static int copy(ByteBuffer destination, ByteBuffer source)
source
into destination
.destination
- the destination buffersource
- the source bufferpublic static int copy(ByteBuffer[] destinations, int offset, int length, ByteBuffer source)
sources
into destinations
in a "scatter" fashion.destinations
- the destination buffersoffset
- the offset into the destination buffers arraylength
- the number of buffers to updatesource
- the source bufferpublic static int copy(ByteBuffer destination, ByteBuffer[] sources, int offset, int length)
sources
into destination
in a "gather" fashion.destination
- the destination buffersources
- the source buffersoffset
- the offset into the source buffers arraylength
- the number of buffers to read frompublic static long copy(ByteBuffer[] destinations, int destOffset, int destLength, ByteBuffer[] sources, int srcOffset, int srcLength)
sources
into destinations
by a combined "scatter"/"gather" operation.destinations
- the destination buffersdestOffset
- the offset into the destination buffers arraydestLength
- the number of buffers to write tosources
- the source bufferssrcOffset
- the offset into the source buffers arraysrcLength
- the number of buffers to read frompublic static int copy(int count, ByteBuffer destination, ByteBuffer source)
count
bytes from source
into destination
.count
- the maximum number of bytes to copydestination
- the destination buffersource
- the source bufferpublic static int copy(int count, ByteBuffer[] destinations, int offset, int length, ByteBuffer source)
count
bytes from sources
into destinations
in a "scatter" fashion.count
- the maximum number of bytes to copydestinations
- the destination buffersoffset
- the offset into the destination buffers arraylength
- the number of buffers to updatesource
- the source bufferpublic static int copy(int count, ByteBuffer destination, ByteBuffer[] sources, int offset, int length)
count
bytes from sources
into destination
in a "gather" fashion.count
- the maximum number of bytes to copydestination
- the destination buffersources
- the source buffersoffset
- the offset into the source buffers arraylength
- the number of buffers to read frompublic static long copy(long count, ByteBuffer[] destinations, int destOffset, int destLength, ByteBuffer[] sources, int srcOffset, int srcLength)
count
bytes from sources
into destinations
by a combined "scatter"/"gather" operation.count
- the maximum number of bytes to copydestinations
- the destination buffersdestOffset
- the offset into the destination buffers arraydestLength
- the number of buffers to write tosources
- the source bufferssrcOffset
- the offset into the source buffers arraysrcLength
- the number of buffers to read frompublic static ByteBuffer fill(ByteBuffer buffer, int value, int count)
buffer
- the buffer to fillvalue
- the value to fillcount
- the number of bytes to fillpublic static CharBuffer slice(CharBuffer buffer, int sliceSize)
buffer
- the buffer to slicesliceSize
- the size of the sliceCharBuffer.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 fillpublic static ShortBuffer slice(ShortBuffer buffer, int sliceSize)
buffer
- the buffer to slicesliceSize
- the size of the sliceShortBuffer.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 fillpublic static IntBuffer slice(IntBuffer buffer, int sliceSize)
buffer
- the buffer to slicesliceSize
- the size of the sliceIntBuffer.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 fillpublic static LongBuffer slice(LongBuffer buffer, int sliceSize)
buffer
- the buffer to slicesliceSize
- the size of the sliceLongBuffer.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 fillpublic static <T extends Buffer> T skip(T buffer, int cnt) throws BufferUnderflowException
T
- the buffer typebuffer
- the buffer to setcnt
- the distance to skipBufferUnderflowException
- if there are fewer than cnt
bytes remainingBuffer.position(int)
public static int trySkip(Buffer buffer, int cnt)
buffer
- the buffer to setcnt
- the distance to skipBuffer.position(int)
public static long trySkip(Buffer[] buffers, int offs, int len, long cnt)
buffers
- the buffers to setoffs
- the offset into the buffers arraylen
- the number of buffers to considercnt
- the distance to skipBuffer.position(int)
public static <T extends Buffer> T unget(T buffer, int cnt)
T
- the buffer typebuffer
- the buffer to setcnt
- the distance to skip backwardsBuffer.position(int)
public static byte[] take(ByteBuffer buffer, int cnt)
buffer
- the buffer to readcnt
- the number of bytes to takepublic static char[] take(CharBuffer buffer, int cnt)
buffer
- the buffer to readcnt
- the number of chars to takepublic static short[] take(ShortBuffer buffer, int cnt)
buffer
- the buffer to readcnt
- the number of shorts to takepublic static int[] take(IntBuffer buffer, int cnt)
buffer
- the buffer to readcnt
- the number of ints to takepublic static long[] take(LongBuffer buffer, int cnt)
buffer
- the buffer to readcnt
- the number of longs to takepublic static byte[] take(ByteBuffer buffer)
buffer
- the buffer to readpublic static char[] take(CharBuffer buffer)
buffer
- the buffer to readpublic static short[] take(ShortBuffer buffer)
buffer
- the buffer to readpublic static int[] take(IntBuffer buffer)
buffer
- the buffer to readpublic static long[] take(LongBuffer buffer)
buffer
- the buffer to readpublic 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 columnspublic 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 columnsIOException
- if an error occurs during appendpublic 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 columnspublic 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 columnsIOException
- if an error occurs during appendpublic static boolean hasRemaining(Buffer[] buffers, int offs, int len)
buffers
- the buffersoffs
- the offset into the buffers arraylen
- the number of buffers to checktrue
if any of the selected buffers has remaining datapublic static boolean hasRemaining(Buffer[] buffers)
buffers
- the bufferstrue
if any of the selected buffers has remaining datapublic static long remaining(Buffer[] buffers, int offs, int len)
buffers
- the buffersoffs
- the offset into the buffers arraylen
- the number of buffers to checkpublic static long remaining(Buffer[] buffers)
buffers
- the bufferspublic static ByteBuffer putModifiedUtf8(ByteBuffer dest, String orig) throws BufferOverflowException
dest
- the byte bufferorig
- the source bytesBufferOverflowException
- 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 bufferBufferUnderflowException
- if the end of the buffer was reached before encountering a 0
public static String getModifiedUtf8(ByteBuffer src) throws BufferUnderflowException
src
- the bufferBufferUnderflowException
- if the buffer ends abruptly in the midst of a single characterpublic 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 buildertrue
if the entire string was read, false
if more data is neededpublic 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 bytestrue
if the entire string was read, false
if more data is neededpublic 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 buildertrue
if the entire string was read, false
if more data is neededpublic 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 bytestrue
if the entire string was read, false
if more data is neededpublic 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 linetrue
if the entire string was read, false
if more data is neededpublic static void readAscii(ByteBuffer src, StringBuilder builder)
'?'
is written
to the string builder in its place.src
- the source bufferbuilder
- the destination builderpublic 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 bytespublic 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 bytespublic 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 buildertrue
if the entire string was read, false
if more data is neededpublic 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 buildertrue
if the entire string was read, false
if more data is neededpublic 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 linetrue
if the entire string was read, false
if more data is neededpublic static void readLatin1(ByteBuffer src, StringBuilder builder)
src
- the source bufferbuilder
- the destination builderpublic 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 buildertrue
if the entire string was read, false
if more data is neededpublic 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 builderreplacement
- the replacement character to usetrue
if the entire string was read, false
if more data is neededpublic 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 buildertrue
if the entire string was read, false
if more data is neededpublic 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 bytestrue
if the entire string was read, false
if more data is neededpublic 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 linetrue
if the entire string was read, false
if more data is neededpublic 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 usetrue
if the entire string was read, false
if more data is neededpublic 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 linetrue
if the entire string was read, false
if more data is neededpublic static <B extends Buffer> Pooled<B> pooledWrapper(B buffer)
B
- the buffer typebuffer
- the buffer to wrappublic static BufferAllocator<ByteBuffer> sliceAllocator(ByteBuffer buffer)
BufferUnderflowException
.buffer
- the source bufferpublic static <B extends Buffer> Pool<B> allocatedBufferPool(BufferAllocator<B> allocator, int size)
B
- the buffer typeallocator
- the buffer allocatorsize
- the buffer sizepublic static Pool<ByteBuffer> secureBufferPool(Pool<ByteBuffer> delegate)
delegate
- the delegate poolpublic static boolean isSecureBufferPool(Pool<?> pool)
pool
- the pool to testtrue
if it is a secure pool instancepublic static void zero(ByteBuffer buffer)
buffer
- the bufferpublic static void zero(CharBuffer buffer)
buffer
- the bufferpublic static boolean isDirect(Buffer... buffers) throws IllegalArgumentException
buffers
- the bufferstrue
if all the buffers are direct, false
if they are all heap buffersIllegalArgumentException
- if both direct and heap buffers were found, or if a buffer is null
public static boolean isDirect(Buffer[] buffers, int offset, int length)
buffers
- the bufferstrue
if all the buffers are direct, false
if they are all heap buffersIllegalArgumentException
- if both direct and heap buffers were found, or if a buffer is null
public static void assertWritable(Buffer[] buffers, int offs, int len) throws ReadOnlyBufferException
buffers
- the buffers arrayoffs
- the offset in the array to start searchinglen
- the number of buffers to checkReadOnlyBufferException
- if any of the buffers are read-onlypublic static void assertWritable(Buffer... buffers) throws ReadOnlyBufferException
buffers
- the buffers arrayReadOnlyBufferException
- if any of the buffers are read-onlypublic static void addRandom(ByteBuffer target, Random random, int count)
count
bytes of random data to the target buffer.target
- the target bufferrandom
- the RNGcount
- the number of bytes to addpublic static void addRandom(ByteBuffer target, int count)
count
bytes of random data to the target buffer using the thread-local RNG.target
- the target buffercount
- the number of bytes to addpublic static void addRandom(ByteBuffer target, Random random)
target
- the target bufferrandom
- the RNGpublic static void addRandom(ByteBuffer target)
target
- the target bufferCopyright © 2012 JBoss by Red Hat. All Rights Reserved.