XNIO API 2.1.0.CR2

org.jboss.xnio
Class Buffers

java.lang.Object
  extended by org.jboss.xnio.Buffers

public final class Buffers
extends Object

Buffer utility methods.


Field Summary
static ByteBuffer EMPTY_BYTE_BUFFER
          The empty byte buffer.
 
Method Summary
static
<T extends Buffer>
T
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
<T extends Buffer>
T
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
<T extends Buffer>
T
limit(T buffer, int limit)
          Set the buffer limit.
static
<T extends Buffer>
T
mark(T buffer)
          Set the buffer mark.
static
<T extends Buffer>
T
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
<T extends Buffer>
T
reset(T buffer)
          Reset the buffer.
static
<T extends Buffer>
T
rewind(T buffer)
          Rewind the buffer.
static
<T extends Buffer>
T
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
<T extends Buffer>
T
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

EMPTY_BYTE_BUFFER

public static final ByteBuffer EMPTY_BYTE_BUFFER
The empty byte buffer.

Method Detail

flip

public static <T extends Buffer> T flip(T buffer)
Flip a buffer.

Type Parameters:
T - the buffer type
Parameters:
buffer - the buffer to flip
Returns:
the buffer instance
See Also:
Buffer.flip()

clear

public static <T extends Buffer> T clear(T buffer)
Clear a buffer.

Type Parameters:
T - the buffer type
Parameters:
buffer - the buffer to clear
Returns:
the buffer instance
See Also:
Buffer.clear()

limit

public static <T extends Buffer> T limit(T buffer,
                                         int limit)
Set the buffer limit.

Type Parameters:
T - the buffer type
Parameters:
buffer - the buffer to set
limit - the new limit
Returns:
the buffer instance
See Also:
Buffer.limit(int)

mark

public static <T extends Buffer> T mark(T buffer)
Set the buffer mark.

Type Parameters:
T - the buffer type
Parameters:
buffer - the buffer to mark
Returns:
the buffer instance
See Also:
Buffer.mark()

position

public static <T extends Buffer> T position(T buffer,
                                            int position)
Set the buffer position.

Type Parameters:
T - the buffer type
Parameters:
buffer - the buffer to set
position - the new position
Returns:
the buffer instance
See Also:
Buffer.position(int)

reset

public static <T extends Buffer> T reset(T buffer)
Reset the buffer.

Type Parameters:
T - the buffer type
Parameters:
buffer - the buffer to reset
Returns:
the buffer instance
See Also:
Buffer.reset()

rewind

public static <T extends Buffer> T rewind(T buffer)
Rewind the buffer.

Type Parameters:
T - the buffer type
Parameters:
buffer - the buffer to rewind
Returns:
the buffer instance
See Also:
Buffer.rewind()

slice

public static ByteBuffer slice(ByteBuffer buffer,
                               int sliceSize)
Slice the buffer. The original buffer's position will be moved up past the slice that was taken.

Parameters:
buffer - the buffer to slice
sliceSize - the size of the slice
Returns:
the buffer slice
See Also:
ByteBuffer.slice()

fill

public static ByteBuffer fill(ByteBuffer buffer,
                              int value,
                              int count)
Fill a buffer with a repeated value.

Parameters:
buffer - the buffer to fill
value - the value to fill
count - the number of bytes to fill
Returns:
the buffer instance

slice

public static CharBuffer slice(CharBuffer buffer,
                               int sliceSize)
Slice the buffer. The original buffer's position will be moved up past the slice that was taken.

Parameters:
buffer - the buffer to slice
sliceSize - the size of the slice
Returns:
the buffer slice
See Also:
CharBuffer.slice()

fill

public static CharBuffer fill(CharBuffer buffer,
                              int value,
                              int count)
Fill a buffer with a repeated value.

Parameters:
buffer - the buffer to fill
value - the value to fill
count - the number of chars to fill
Returns:
the buffer instance

slice

public static ShortBuffer slice(ShortBuffer buffer,
                                int sliceSize)
Slice the buffer. The original buffer's position will be moved up past the slice that was taken.

Parameters:
buffer - the buffer to slice
sliceSize - the size of the slice
Returns:
the buffer slice
See Also:
ShortBuffer.slice()

fill

public static ShortBuffer fill(ShortBuffer buffer,
                               int value,
                               int count)
Fill a buffer with a repeated value.

Parameters:
buffer - the buffer to fill
value - the value to fill
count - the number of shorts to fill
Returns:
the buffer instance

slice

public static IntBuffer slice(IntBuffer buffer,
                              int sliceSize)
Slice the buffer. The original buffer's position will be moved up past the slice that was taken.

Parameters:
buffer - the buffer to slice
sliceSize - the size of the slice
Returns:
the buffer slice
See Also:
IntBuffer.slice()

fill

public static IntBuffer fill(IntBuffer buffer,
                             int value,
                             int count)
Fill a buffer with a repeated value.

Parameters:
buffer - the buffer to fill
value - the value to fill
count - the number of ints to fill
Returns:
the buffer instance

slice

public static LongBuffer slice(LongBuffer buffer,
                               int sliceSize)
Slice the buffer. The original buffer's position will be moved up past the slice that was taken.

Parameters:
buffer - the buffer to slice
sliceSize - the size of the slice
Returns:
the buffer slice
See Also:
LongBuffer.slice()

fill

public static LongBuffer fill(LongBuffer buffer,
                              long value,
                              int count)
Fill a buffer with a repeated value.

Parameters:
buffer - the buffer to fill
value - the value to fill
count - the number of longs to fill
Returns:
the buffer instance

skip

public static <T extends Buffer> T skip(T buffer,
                                        int cnt)
Advance a buffer's position relative to its current position.

Type Parameters:
T - the buffer type
Parameters:
buffer - the buffer to set
cnt - the distantce to skip
Returns:
the buffer instance
See Also:
Buffer.position(int)

unget

public static <T extends Buffer> T unget(T buffer,
                                         int cnt)
Rewind a buffer's position relative to its current position.

Type Parameters:
T - the buffer type
Parameters:
buffer - the buffer to set
cnt - the distantce to skip backwards
Returns:
the buffer instance
See Also:
Buffer.position(int)

take

public static byte[] take(ByteBuffer buffer,
                          int cnt)
Take a certain number of bytes from the buffer and return them in an array.

Parameters:
buffer - the buffer to read
cnt - the number of bytes to take
Returns:
the bytes

take

public static char[] take(CharBuffer buffer,
                          int cnt)
Take a certain number of chars from the buffer and return them in an array.

Parameters:
buffer - the buffer to read
cnt - the number of chars to take
Returns:
the chars

take

public static short[] take(ShortBuffer buffer,
                           int cnt)
Take a certain number of shorts from the buffer and return them in an array.

Parameters:
buffer - the buffer to read
cnt - the number of shorts to take
Returns:
the shorts

take

public static int[] take(IntBuffer buffer,
                         int cnt)
Take a certain number of ints from the buffer and return them in an array.

Parameters:
buffer - the buffer to read
cnt - the number of ints to take
Returns:
the ints

take

public static long[] take(LongBuffer buffer,
                          int cnt)
Take a certain number of longs from the buffer and return them in an array.

Parameters:
buffer - the buffer to read
cnt - the number of longs to take
Returns:
the longs

createDumper

public 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. Useful for logging byte buffers; if the toString() method is never called, the process of dumping the buffer is never performed.

Parameters:
buffer - the buffer
indent - the indentation to use
columns - the number of 8-byte columns
Returns:
a stringable object

dump

public static void dump(ByteBuffer buffer,
                        Appendable dest,
                        int indent,
                        int columns)
                 throws IOException
Dump a byte buffer to the given target.

Parameters:
buffer - the buffer
dest - the target
indent - the indentation to use
columns - the number of 8-byte columns
Throws:
IOException - if an error occurs during append

createDumper

public 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. Useful for logging character buffers; if the toString() method is never called, the process of dumping the buffer is never performed.

Parameters:
buffer - the buffer
indent - the indentation to use
columns - the number of 8-byte columns
Returns:
a stringable object

dump

public static void dump(CharBuffer buffer,
                        Appendable dest,
                        int indent,
                        int columns)
                 throws IOException
Dump a character buffer to the given target.

Parameters:
buffer - the buffer
dest - the target
indent - the indentation to use
columns - the number of 8-byte columns
Throws:
IOException - if an error occurs during append

createHeapByteBufferAllocator

public static Pool<ByteBuffer> createHeapByteBufferAllocator(int size)
Create a heap-based buffer allocator.

Parameters:
size - the size of the returned buffers
Returns:
the buffer allocator
Since:
1.1

hasRemaining

public static boolean hasRemaining(Buffer[] buffers,
                                   int offs,
                                   int len)
Determine whether any of the buffers has remaining data.

Parameters:
buffers - the buffers
offs - the offset into the buffers array
len - the number of buffers to check
Returns:
true if any of the selected buffers has remaining data

hasRemaining

public static boolean hasRemaining(Buffer[] buffers)
Determine whether any of the buffers has remaining data.

Parameters:
buffers - the buffers
Returns:
true if any of the selected buffers has remaining data

remaining

public static long remaining(Buffer[] buffers,
                             int offs,
                             int len)
Get the total remaining size of all the given buffers.

Parameters:
buffers - the buffers
offs - the offset into the buffers array
len - the number of buffers to check
Returns:
the number of remaining elements

remaining

public static long remaining(Buffer[] buffers)
Get the total remaining size of all the given buffers.

Parameters:
buffers - the buffers
Returns:
the number of remaining elements

put

public 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.

Parameters:
dsts - the destination buffers
doffs - the offset into the destination buffers array
dlen - the number of buffers to update
src - the source buffer

putModifiedUtf8

public static ByteBuffer putModifiedUtf8(ByteBuffer dest,
                                         String orig)
                                  throws BufferOverflowException
Put the string into the byte buffer, encoding it using "modified UTF-8" encoding.

Parameters:
dest - the byte buffer
orig - the source bytes
Returns:
the byte buffer
Throws:
BufferOverflowException - if there is not enough space in the buffer for the complete string
See Also:
DataOutput.writeUTF(String)

getModifiedUtf8Z

public static String getModifiedUtf8Z(ByteBuffer src)
                               throws BufferUnderflowException
Get a 0-terminated string from the byte buffer, decoding it using "modified UTF-8" encoding.

Parameters:
src - the source buffer
Returns:
the string
Throws:
BufferUnderflowException - if the end of the buffer was reached before encountering a 0

getModifiedUtf8

public static String getModifiedUtf8(ByteBuffer src)
                              throws BufferUnderflowException
Get a modified UTF-8 string from the remainder of the buffer.

Parameters:
src - the buffer
Returns:
the modified UTF-8 string
Throws:
BufferUnderflowException - if the buffer ends abruptly in the midst of a single character

readAsciiZ

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
Returns:
true if the entire string was read, false if more data is needed

readAsciiZ

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
replacement - the replacement character for invalid bytes
Returns:
true if the entire string was read, false if more data is needed

readAsciiLine

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
Returns:
true if the entire string was read, false if more data is needed

readAsciiLine

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
replacement - the replacement character for invalid bytes
Returns:
true if the entire string was read, false if more data is needed

readAsciiLine

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
replacement - the replacement character for invalid bytes
delimiter - the character which marks the end of the line
Returns:
true if the entire string was read, false if more data is needed

readAscii

public static void readAscii(ByteBuffer src,
                             StringBuilder builder)
Read the remainder of a buffer as ASCII text, appending the results to the given string builder. If an invalid byte is read, the character '?' is written to the string builder in its place.

Parameters:
src - the source buffer
builder - the destination builder

readAscii

public 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. If an invalid byte is read, the character designated by replacement is written to the string builder in its place.

Parameters:
src - the source buffer
builder - the destination builder
replacement - the replacement character for invalid bytes

readAscii

public 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. If an invalid byte is read, the character designated by replacement is written to the string builder in its place.

Parameters:
src - the source buffer
builder - the destination builder
limit - the maximum number of characters to write
replacement - the replacement character for invalid bytes

readLatin1Z

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
Returns:
true if the entire string was read, false if more data is needed

readLatin1Line

public 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. 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. The EOL character will be included in the resultant string.

Parameters:
src - the source buffer
builder - the destination builder
Returns:
true if the entire string was read, false if more data is needed

readLatin1Line

public 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. 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. The delimiter character will be included in the resultant string.

Parameters:
src - the source buffer
builder - the destination builder
delimiter - the character which marks the end of the line
Returns:
true if the entire string was read, false if more data is needed

readLatin1

public static void readLatin1(ByteBuffer src,
                              StringBuilder builder)
Read the remainder of a buffer as ASCII text, appending the results to the given string builder.

Parameters:
src - the source buffer
builder - the destination builder

readModifiedUtf8Z

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
Returns:
true if the entire string was read, false if more data is needed

readModifiedUtf8Z

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
Returns:
true if the entire string was read, false if more data is needed

readModifiedUtf8Line

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
Returns:
true if the entire string was read, false if more data is needed

readModifiedUtf8Line

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
replacement - the replacement character for invalid bytes
Returns:
true if the entire string was read, false if more data is needed

readModifiedUtf8Line

public 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
replacement - the replacement character for invalid bytes
delimiter - the character which marks the end of the line
Returns:
true if the entire string was read, false if more data is needed

readLine

public 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. 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
decoder - the decoder to use
Returns:
true if the entire string was read, false if more data is needed

readLine

public 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. 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. 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.

Parameters:
src - the source buffer
builder - the destination builder
decoder - the decoder to use
delimiter - the character which marks the end of the line
Returns:
true if the entire string was read, false if more data is needed

XNIO API 2.1.0.CR2

Copyright © 2010 JBoss, a division of Red Hat, Inc.