XNIO version 1.2.1.GA

org.jboss.xnio
Class Buffers

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

public final class Buffers
extends Object

Buffer utility methods.


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 BufferAllocator<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
<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
<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)
          Set 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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)
Set 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)

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 BufferAllocator<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

XNIO version 1.2.1.GA

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