Top Description Fields Constructors Methods
org.eclipse.jetty.util

public Class BufferUtil

extends Object
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, .OutputStream, java.nio.Buffer, .BufferOverflowException, .ByteBuffer, .ByteOrder, java.nio.channels.FileChannel, .FileChannel.MapMode, .ReadableByteChannel, .SeekableByteChannel, java.nio.charset.Charset, .StandardCharsets, java.nio.file.Files, .Path, .StandardOpenOption, java.util.Arrays, org.eclipse.jetty.util.resource.Resource, org.slf4j.Logger, .LoggerFactory

Buffer utility methods.

The standard JVM ByteBuffer can exist in two modes: In fill mode the valid data is between 0 and pos; In flush mode the valid data is between the pos and the limit. The various ByteBuffer methods assume a mode and some of them will switch or enforce a mode: Allocate and clear set fill mode; flip and compact switch modes; read and write assume fill and flush modes. This duality can result in confusing code such as:

    buffer.clear();
    channel.write(buffer);

Which looks as if it should write no data, but in fact writes the buffer worth of garbage.

The BufferUtil class provides a set of utilities that operate on the convention that ByteBuffers will always be left, passed in an API or returned from a method in the flush mode - ie with valid data between the pos and limit. This convention is adopted so as to avoid confusion as to what state a buffer is in and to avoid excessive copying of data that can result with the usage of compress.

Thus this class provides alternate implementations of allocate(int), allocateDirect(int) and clear(ByteBuffer) that leave the buffer in flush mode. Thus the following tests will pass:

    ByteBuffer buffer = BufferUtil.allocate(1024);
    assert(buffer.remaining()==0);
    BufferUtil.clear(buffer);
    assert(buffer.remaining()==0);

If the BufferUtil methods fill(ByteBuffer, byte[], int, int), append(ByteBuffer, byte[], int, int) or put(ByteBuffer, ByteBuffer) are used, then the caller does not need to explicitly switch the buffer to fill mode. If the caller wishes to use other ByteBuffer bases libraries to fill a buffer, then they can use explicit calls of #flipToFill(ByteBuffer) and #flipToFlush(ByteBuffer, int) to change modes. Note because this convention attempts to avoid the copies of compact, the position is not set to zero on each fill cycle and so its value must be remembered:

     int pos = BufferUtil.flipToFill(buffer);
     try
     {
         buffer.put(data);
     }
     finally
     {
         flipToFlush(buffer, pos);
     }

The flipToFill method will effectively clear the buffer if it is empty and will compact the buffer if there is no space.

Field Summary

Modifier and TypeField and Description
private static final int[]
private static final long[]
pack-priv static final byte[]
public static final ByteBuffer
private static final int[]
private static final Logger
pack-priv static final byte
pack-priv static final byte
pack-priv static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static ByteBuffer

Returns:

Buffer
allocate
(int
capacity of the allocated ByteBuffer
capacity
)

Allocate ByteBuffer in flush mode.

public static ByteBuffer

Returns:

the newly allocated ByteBuffer
allocate
(int
capacity of the allocated ByteBuffer
capacity
,
boolean
whether the ByteBuffer is direct
direct
)

Allocates a ByteBuffer in flush mode.

public static ByteBuffer

Returns:

Buffer
allocateDirect
(int
capacity of the allocated ByteBuffer
capacity
)

Allocate ByteBuffer in flush mode.

public static void
append(ByteBuffer
Buffer is flush mode
to
,
byte[]
bytes to append
b
,
int
offset into byte
off
,
int
length to append
len
)

Append bytes to a buffer.

public static void
append(ByteBuffer
Buffer is flush mode
to
,
byte[]
bytes to append
b
)

Append bytes to a buffer.

public static void
append(ByteBuffer
Buffer is flush mode
to
,
String
String to append as UTF8
s
)

Append a string to a buffer.

public static void
append(ByteBuffer
Buffer is flush mode
to
,
byte
byte to append
b
)

Appends a byte to a buffer

public static int

Returns:

The position of the valid data before the flipped position.
append
(ByteBuffer
Buffer is flush mode
to
,
ByteBuffer
buffer to append
b
)

Appends a buffer to a buffer

private static void
private static void
public static void
clear(ByteBuffer
the buffer to clear.
buffer
)

Clears the buffer to be empty in flush mode.

public static void
clearToFill(ByteBuffer
The buffer to clear.
buffer
)

Clear the buffer to be empty in fill mode.

public static boolean

Returns:

true if the compact made a full buffer have space
compact
(ByteBuffer
the buffer to compact
buffer
)

Compact the buffer

public static ByteBuffer

Returns:

A copy of the buffer
copy
(ByteBuffer
The buffer to copy
buffer
)

Deep copy of a buffer

public static ByteBuffer
ensureCapacity(ByteBuffer buffer, int capacity)

public static int

Returns:

the number of bytes taken from the buffer.
fill
(ByteBuffer
Buffer The buffer to fill to. The buffer will be flipped to fill mode and then flipped back to flush mode.
to
,
byte[]
bytes The bytes to fill
b
,
int
offset into bytes
off
,
int
length to fill
len
)

Like append, but does not throw BufferOverflowException

public static int

Returns:

The position of the valid data before the flipped position. This value should be passed to a subsequent call to flipToFlush(ByteBuffer, int)
flipToFill
(ByteBuffer
The buffer to flip
buffer
)

Flip the buffer to fill mode.

public static void
flipToFlush(ByteBuffer
the buffer to be flipped
buffer
,
int
The position of valid data to flip to. This should be the return value of the previous call to flipToFill(ByteBuffer)
position
)

Flip the buffer to Flush mode.

public static boolean

Returns:

true if the buffer is not null and not empty.
hasContent
(ByteBuffer
the buffer to check
buf
)

Check for a non null and non empty buffer.

private static void
idString(ByteBuffer buffer, StringBuilder out)

Convert Buffer to string ID independent of content

public static boolean

Returns:

true if the buffer is null or empty.
isEmpty
(ByteBuffer
the buffer to check
buf
)

Check for an empty or null buffer.

public static boolean

Returns:

true if the buffer is null or empty.
isEmpty
(ByteBuffer[]
the buffer to check
buf
)

Check for an empty or null buffers.

public static boolean

Returns:

true if the buffer is not null and the limit equals the capacity.
isFull
(ByteBuffer
the buffer to check
buf
)

Check for a non null and full buffer.

public static boolean
isPrefix(ByteBuffer prefix, ByteBuffer buffer)

public static boolean
isTheEmptyBuffer(ByteBuffer
the buffer to check
buf
)

Returns: true if buf is equal to EMPTY_BUFFER

public static int

Returns:

0 if the buffer is null, else the bytes remaining in the buffer.
length
(ByteBuffer
The buffer to get the remaining from, in flush mode.
buffer
)

Get remaining from null checked buffer

public static int

Returns:

number of bytes moved
put
(ByteBuffer
Buffer to take bytes from in flush mode
from
,
ByteBuffer
Buffer to put bytes to in fill mode.
to
)

Put data from one buffer into another, avoiding over/under flows

public static void
public static void
putDecInt(ByteBuffer buffer, int n)

public static void
putDecLong(ByteBuffer buffer, long n)

public static void
putHexInt(ByteBuffer buffer, int n)

public static void
putIntLittleEndian(ByteBuffer
The buffer to put to
buffer
,
int
The value to put.
value
)

Put an integer little endian

public static void
readFrom(File file, ByteBuffer buffer)

public static void
readFrom(Path path, ByteBuffer buffer)

public static int

Returns:

the number of bytes read into the buffer.
readFrom
(ReadableByteChannel
the channel to read from.
readableByteChannel
,
ByteBuffer
the buffer to read into.
byteBuffer
)

Read content from a ReadableByteChannel into a buffer.

public static void
readFrom(InputStream is, int needed, ByteBuffer buffer)

public static int
public static long

Returns:

number of bytes remaining in all buffers.
remaining
(ByteBuffer...
the buffers to check
buf
)

Get the remaining bytes in 0 or more buffers.

public static void
reset(ByteBuffer
the buffer to reset.
buffer
)

Resets the buffer's endianness to ByteOrder#BIG_ENDIAN and clears the buffer to be empty in flush mode.

public static int

Returns:

space
space
(ByteBuffer
the buffer to get the space from
buffer
)

Get the space from the limit to the capacity

public static int

Returns:

an int
takeInt
(ByteBuffer
A buffer containing an integer in flush mode. The position is updated.
buffer
)

Convert buffer to an integer.

public static byte[]

Returns:

An array of bytes duplicated from the buffer.
toArray
(ByteBuffer
The buffer to convert in flush mode. The buffer is not altered.
buffer
)

Convert a ByteBuffer to a byte array.

public static ByteBuffer
toBuffer(int value)

public static ByteBuffer
toBuffer(long value)

public static ByteBuffer
public static ByteBuffer
toBuffer(String s, Charset charset)

public static ByteBuffer

Returns:

ByteBuffer with provided byte array, in flush mode
toBuffer
(byte[]
the byte array to back buffer with.
array
)

Create a new ByteBuffer using provided byte array.

public static ByteBuffer

Returns:

ByteBuffer with provided byte array, in flush mode
toBuffer
(byte[]
the byte array to use.
array
,
int
the offset within the byte array to use from
offset
,
int
the length in bytes of the array to use
length
)

Create a new ByteBuffer using the provided byte array.

public static ByteBuffer
toBuffer(Resource resource, boolean direct)

public static String
public static String

Returns:

A string showing the pointers and content of the buffer
toDetailString
(ByteBuffer
the buffer to generate a detail string from
buffer
)

Convert Buffer to a detail debug string of pointers and content

public static ByteBuffer
public static ByteBuffer
public static String

Returns:

A hex string
toHexString
(ByteBuffer
the buffer to generate a hex byte summary from
buffer
)

Convert buffer to a Hex String.

public static String

Returns:

A string showing a summary of the content in hex
toHexSummary
(ByteBuffer
the buffer to generate a hex byte summary from
buffer
)

Convert buffer to a Hex Summary String.

public static String

Returns:

A string showing the buffer ID
toIDString
(ByteBuffer
the buffet to generate a string ID from
buffer
)

Convert Buffer to string ID independent of content

public static int

Returns:

an int
toInt
(ByteBuffer
A buffer containing an integer in flush mode. The position is not changed.
buffer
)

Convert buffer to an integer.

public static int

Returns:

an int of the buffer bytes
toInt
(ByteBuffer
A buffer containing an integer in flush mode. The position is not changed.
buffer
,
int
the position in the buffer to start reading from
position
,
int
the length of the buffer to use for conversion
length
)

Convert buffer to an integer.

public static long

Returns:

an int
toLong
(ByteBuffer
A buffer containing an integer in flush mode. The position is not changed.
buffer
)

Convert buffer to an long.

public static ByteBuffer
public static ByteBuffer
toMappedBuffer(Path filePath, long pos, long len)

public static ByteBuffer
public static ByteBuffer
toMappedBuffer(Resource resource, long pos, long len)

public static String

Returns:

The buffer as a string.
toString
(ByteBuffer
The buffer to convert in flush mode. The buffer is unchanged
buffer
)

Convert the buffer to an ISO-8859-1 String

public static String

Returns:

The buffer as a string.
toString
(ByteBuffer
The buffer to convert in flush mode. The buffer is unchanged
buffer
,
Charset
The Charset to use to convert the bytes
charset
)

Convert the buffer to an ISO-8859-1 String

public static String

Returns:

The buffer as a string.
toString
(ByteBuffer
the buffer to convert
buffer
,
int
The position in the buffer to start the string from
position
,
int
The length of the buffer
length
,
Charset
The Charset to use to convert the bytes
charset
)

Convert a partial buffer to a String.

public static String
public static String

Returns:

The buffer as a string.
toUTF8String
(ByteBuffer
The buffer to convert in flush mode. The buffer is unchanged
buffer
)

Convert the buffer to an UTF-8 String

public static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decDivisorsback to summary
private static final int[] decDivisors
decDivisorsLback to summary
private static final long[] decDivisorsL
DIGITback to summary
pack-priv static final byte[] DIGIT
EMPTY_BUFFERback to summary
public static final ByteBuffer EMPTY_BUFFER
hexDivisorsback to summary
private static final int[] hexDivisors
LOGback to summary
private static final Logger LOG
MINUSback to summary
pack-priv static final byte MINUS
SPACEback to summary
pack-priv static final byte SPACE
TEMP_BUFFER_SIZEback to summary
pack-priv static final int TEMP_BUFFER_SIZE

Constructor Detail

BufferUtilback to summary
public BufferUtil()

Method Detail

allocateback to summary
public static ByteBuffer allocate(int capacity)

Allocate ByteBuffer in flush mode. The position and limit will both be zero, indicating that the buffer is empty and must be flipped before any data is put to it.

Parameters
capacity:int

capacity of the allocated ByteBuffer

Returns:ByteBuffer

Buffer

allocateback to summary
public static ByteBuffer allocate(int capacity, boolean direct)

Allocates a ByteBuffer in flush mode. The position and limit will both be zero, indicating that the buffer is empty and must be flipped before any data is put to it.

Parameters
capacity:int

capacity of the allocated ByteBuffer

direct:boolean

whether the ByteBuffer is direct

Returns:ByteBuffer

the newly allocated ByteBuffer

allocateDirectback to summary
public static ByteBuffer allocateDirect(int capacity)

Allocate ByteBuffer in flush mode. The position and limit will both be zero, indicating that the buffer is empty and in flush mode.

Parameters
capacity:int

capacity of the allocated ByteBuffer

Returns:ByteBuffer

Buffer

appendback to summary
public static void append(ByteBuffer to, byte[] b, int off, int len) throws BufferOverflowException

Append bytes to a buffer.

Parameters
to:ByteBuffer

Buffer is flush mode

b:byte[]

bytes to append

off:int

offset into byte

len:int

length to append

Exceptions
BufferOverflowException:
if unable to append buffer due to space limits
appendback to summary
public static void append(ByteBuffer to, byte[] b) throws BufferOverflowException

Append bytes to a buffer.

Parameters
to:ByteBuffer

Buffer is flush mode

b:byte[]

bytes to append

Exceptions
BufferOverflowException:
if unable to append buffer due to space limits
appendback to summary
public static void append(ByteBuffer to, String s) throws BufferOverflowException

Append a string to a buffer.

Parameters
to:ByteBuffer

Buffer is flush mode

s:String

String to append as UTF8

Exceptions
BufferOverflowException:
if unable to append buffer due to space limits
appendback to summary
public static void append(ByteBuffer to, byte b)

Appends a byte to a buffer

Parameters
to:ByteBuffer

Buffer is flush mode

b:byte

byte to append

Exceptions
BufferOverflowException:
if unable to append buffer due to space limits
appendback to summary
public static int append(ByteBuffer to, ByteBuffer b)

Appends a buffer to a buffer

Parameters
to:ByteBuffer

Buffer is flush mode

b:ByteBuffer

buffer to append

Returns:int

The position of the valid data before the flipped position.

appendContentCharback to summary
private static void appendContentChar(StringBuilder buf, byte b)
appendDebugStringback to summary
private static void appendDebugString(StringBuilder buf, ByteBuffer buffer)
clearback to summary
public static void clear(ByteBuffer buffer)

Clears the buffer to be empty in flush mode. The position and limit are set to 0.

Parameters
buffer:ByteBuffer

the buffer to clear.

clearToFillback to summary
public static void clearToFill(ByteBuffer buffer)

Clear the buffer to be empty in fill mode. The position is set to 0 and the limit is set to the capacity.

Parameters
buffer:ByteBuffer

The buffer to clear.

compactback to summary
public static boolean compact(ByteBuffer buffer)

Compact the buffer

Parameters
buffer:ByteBuffer

the buffer to compact

Returns:boolean

true if the compact made a full buffer have space

copyback to summary
public static ByteBuffer copy(ByteBuffer buffer)

Deep copy of a buffer

Parameters
buffer:ByteBuffer

The buffer to copy

Returns:ByteBuffer

A copy of the buffer

ensureCapacityback to summary
public static ByteBuffer ensureCapacity(ByteBuffer buffer, int capacity)
fillback to summary
public static int fill(ByteBuffer to, byte[] b, int off, int len)

Like append, but does not throw BufferOverflowException

Parameters
to:ByteBuffer

Buffer The buffer to fill to. The buffer will be flipped to fill mode and then flipped back to flush mode.

b:byte[]

bytes The bytes to fill

off:int

offset into bytes

len:int

length to fill

Returns:int

the number of bytes taken from the buffer.

flipToFillback to summary
public static int flipToFill(ByteBuffer buffer)

Flip the buffer to fill mode. The position is set to the first unused position in the buffer (the old limit) and the limit is set to the capacity. If the buffer is empty, then this call is effectively clearToFill(ByteBuffer). If there is no unused space to fill, a ByteBuffer#compact() is done to attempt to create space.

This method is used as a replacement to ByteBuffer#compact().

Parameters
buffer:ByteBuffer

The buffer to flip

Returns:int

The position of the valid data before the flipped position. This value should be passed to a subsequent call to flipToFlush(ByteBuffer, int)

flipToFlushback to summary
public static void flipToFlush(ByteBuffer buffer, int position)

Flip the buffer to Flush mode. The limit is set to the first unused byte(the old position) and the position is set to the passed position.

This method is used as a replacement of Buffer#flip().

Parameters
buffer:ByteBuffer

the buffer to be flipped

position:int

The position of valid data to flip to. This should be the return value of the previous call to flipToFill(ByteBuffer)

hasContentback to summary
public static boolean hasContent(ByteBuffer buf)

Check for a non null and non empty buffer.

Parameters
buf:ByteBuffer

the buffer to check

Returns:boolean

true if the buffer is not null and not empty.

idStringback to summary
private static void idString(ByteBuffer buffer, StringBuilder out)

Convert Buffer to string ID independent of content

isEmptyback to summary
public static boolean isEmpty(ByteBuffer buf)

Check for an empty or null buffer.

Parameters
buf:ByteBuffer

the buffer to check

Returns:boolean

true if the buffer is null or empty.

isEmptyback to summary
public static boolean isEmpty(ByteBuffer[] buf)

Check for an empty or null buffers.

Parameters
buf:ByteBuffer[]

the buffer to check

Returns:boolean

true if the buffer is null or empty.

isFullback to summary
public static boolean isFull(ByteBuffer buf)

Check for a non null and full buffer.

Parameters
buf:ByteBuffer

the buffer to check

Returns:boolean

true if the buffer is not null and the limit equals the capacity.

isPrefixback to summary
public static boolean isPrefix(ByteBuffer prefix, ByteBuffer buffer)
isTheEmptyBufferback to summary
public static boolean isTheEmptyBuffer(ByteBuffer buf)
Parameters
buf:ByteBuffer

the buffer to check

Returns:boolean

true if buf is equal to EMPTY_BUFFER

lengthback to summary
public static int length(ByteBuffer buffer)

Get remaining from null checked buffer

Parameters
buffer:ByteBuffer

The buffer to get the remaining from, in flush mode.

Returns:int

0 if the buffer is null, else the bytes remaining in the buffer.

putback to summary
public static int put(ByteBuffer from, ByteBuffer to)

Put data from one buffer into another, avoiding over/under flows

Parameters
from:ByteBuffer

Buffer to take bytes from in flush mode

to:ByteBuffer

Buffer to put bytes to in fill mode.

Returns:int

number of bytes moved

putCRLFback to summary
public static void putCRLF(ByteBuffer buffer)
putDecIntback to summary
public static void putDecInt(ByteBuffer buffer, int n)
putDecLongback to summary
public static void putDecLong(ByteBuffer buffer, long n)
putHexIntback to summary
public static void putHexInt(ByteBuffer buffer, int n)
putIntLittleEndianback to summary
public static void putIntLittleEndian(ByteBuffer buffer, int value)

Put an integer little endian

Parameters
buffer:ByteBuffer

The buffer to put to

value:int

The value to put.

readFromback to summary
public static void readFrom(File file, ByteBuffer buffer) throws IOException
readFromback to summary
public static void readFrom(Path path, ByteBuffer buffer) throws IOException
readFromback to summary
public static int readFrom(ReadableByteChannel readableByteChannel, ByteBuffer byteBuffer) throws IOException

Read content from a ReadableByteChannel into a buffer. This may spin if ReadableByteChannel#read(ByteBuffer) returns 0 in which case this will call Thread#onSpinWait().

Parameters
readableByteChannel:ReadableByteChannel

the channel to read from.

byteBuffer:ByteBuffer

the buffer to read into.

Returns:int

the number of bytes read into the buffer.

Exceptions
IOException:
if an I/O error occurs.
readFromback to summary
public static void readFrom(InputStream is, int needed, ByteBuffer buffer) throws IOException
readFromback to summary
public static int readFrom(InputStream is, ByteBuffer buffer) throws IOException
remainingback to summary
public static long remaining(ByteBuffer... buf)

Get the remaining bytes in 0 or more buffers.

Parameters
buf:ByteBuffer[]

the buffers to check

Returns:long

number of bytes remaining in all buffers.

resetback to summary
public static void reset(ByteBuffer buffer)

Resets the buffer's endianness to ByteOrder#BIG_ENDIAN and clears the buffer to be empty in flush mode. The position and limit are set to 0.

Parameters
buffer:ByteBuffer

the buffer to reset.

spaceback to summary
public static int space(ByteBuffer buffer)

Get the space from the limit to the capacity

Parameters
buffer:ByteBuffer

the buffer to get the space from

Returns:int

space

takeIntback to summary
public static int takeInt(ByteBuffer buffer)

Convert buffer to an integer. Parses up to the first non-numeric character. If no number is found an IllegalArgumentException is thrown

Parameters
buffer:ByteBuffer

A buffer containing an integer in flush mode. The position is updated.

Returns:int

an int

toArrayback to summary
public static byte[] toArray(ByteBuffer buffer)

Convert a ByteBuffer to a byte array.

Parameters
buffer:ByteBuffer

The buffer to convert in flush mode. The buffer is not altered.

Returns:byte[]

An array of bytes duplicated from the buffer.

toBufferback to summary
public static ByteBuffer toBuffer(int value)
toBufferback to summary
public static ByteBuffer toBuffer(long value)
toBufferback to summary
public static ByteBuffer toBuffer(String s)
toBufferback to summary
public static ByteBuffer toBuffer(String s, Charset charset)
toBufferback to summary
public static ByteBuffer toBuffer(byte[] array)

Create a new ByteBuffer using provided byte array.

Parameters
array:byte[]

the byte array to back buffer with.

Returns:ByteBuffer

ByteBuffer with provided byte array, in flush mode

toBufferback to summary
public static ByteBuffer toBuffer(byte[] array, int offset, int length)

Create a new ByteBuffer using the provided byte array.

Parameters
array:byte[]

the byte array to use.

offset:int

the offset within the byte array to use from

length:int

the length in bytes of the array to use

Returns:ByteBuffer

ByteBuffer with provided byte array, in flush mode

toBufferback to summary
public static ByteBuffer toBuffer(Resource resource, boolean direct) throws IOException
toDetailStringback to summary
public static String toDetailString(ByteBuffer[] buffer)
toDetailStringback to summary
public static String toDetailString(ByteBuffer buffer)

Convert Buffer to a detail debug string of pointers and content

Parameters
buffer:ByteBuffer

the buffer to generate a detail string from

Returns:String

A string showing the pointers and content of the buffer

toDirectBufferback to summary
public static ByteBuffer toDirectBuffer(String s)
toDirectBufferback to summary
public static ByteBuffer toDirectBuffer(String s, Charset charset)
toHexStringback to summary
public static String toHexString(ByteBuffer buffer)

Convert buffer to a Hex String.

Parameters
buffer:ByteBuffer

the buffer to generate a hex byte summary from

Returns:String

A hex string

toHexSummaryback to summary
public static String toHexSummary(ByteBuffer buffer)

Convert buffer to a Hex Summary String.

Parameters
buffer:ByteBuffer

the buffer to generate a hex byte summary from

Returns:String

A string showing a summary of the content in hex

toIDStringback to summary
public static String toIDString(ByteBuffer buffer)

Convert Buffer to string ID independent of content

Parameters
buffer:ByteBuffer

the buffet to generate a string ID from

Returns:String

A string showing the buffer ID

toIntback to summary
public static int toInt(ByteBuffer buffer)

Convert buffer to an integer. Parses up to the first non-numeric character. If no number is found an IllegalArgumentException is thrown

Parameters
buffer:ByteBuffer

A buffer containing an integer in flush mode. The position is not changed.

Returns:int

an int

toIntback to summary
public static int toInt(ByteBuffer buffer, int position, int length)

Convert buffer to an integer. Parses up to the first non-numeric character. If no number is found an IllegalArgumentException is thrown

Parameters
buffer:ByteBuffer

A buffer containing an integer in flush mode. The position is not changed.

position:int

the position in the buffer to start reading from

length:int

the length of the buffer to use for conversion

Returns:int

an int of the buffer bytes

toLongback to summary
public static long toLong(ByteBuffer buffer)

Convert buffer to an long. Parses up to the first non-numeric character. If no number is found an IllegalArgumentException is thrown

Parameters
buffer:ByteBuffer

A buffer containing an integer in flush mode. The position is not changed.

Returns:long

an int

toMappedBufferback to summary
public static ByteBuffer toMappedBuffer(Path path) throws IOException
toMappedBufferback to summary
public static ByteBuffer toMappedBuffer(Path filePath, long pos, long len) throws IOException
toMappedBufferback to summary
public static ByteBuffer toMappedBuffer(Resource resource) throws IOException
toMappedBufferback to summary
public static ByteBuffer toMappedBuffer(Resource resource, long pos, long len) throws IOException
toStringback to summary
public static String toString(ByteBuffer buffer)

Convert the buffer to an ISO-8859-1 String

Parameters
buffer:ByteBuffer

The buffer to convert in flush mode. The buffer is unchanged

Returns:String

The buffer as a string.

toStringback to summary
public static String toString(ByteBuffer buffer, Charset charset)

Convert the buffer to an ISO-8859-1 String

Parameters
buffer:ByteBuffer

The buffer to convert in flush mode. The buffer is unchanged

charset:Charset

The Charset to use to convert the bytes

Returns:String

The buffer as a string.

toStringback to summary
public static String toString(ByteBuffer buffer, int position, int length, Charset charset)

Convert a partial buffer to a String.

Parameters
buffer:ByteBuffer

the buffer to convert

position:int

The position in the buffer to start the string from

length:int

The length of the buffer

charset:Charset

The Charset to use to convert the bytes

Returns:String

The buffer as a string.

toSummaryStringback to summary
public static String toSummaryString(ByteBuffer buffer)
toUTF8Stringback to summary
public static String toUTF8String(ByteBuffer buffer)

Convert the buffer to an UTF-8 String

Parameters
buffer:ByteBuffer

The buffer to convert in flush mode. The buffer is unchanged

Returns:String

The buffer as a string.

writeToback to summary
public static void writeTo(ByteBuffer buffer, OutputStream out) throws IOException