|
Sea 0.2.2 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object gov.lbl.dsd.sea.nio.util.BufferUtil
Various utilities related to the ByteBuffer
buffers; in particular
String conversions using a Charset
.
Method Summary | |
static ByteBuffer |
concat(ByteBuffer[] buffers)
Creates and returns a new buffer containing the remaining bytes in the given buffers; Leaves the input buffers unmodified. |
static ByteBuffer |
copy(ByteBuffer src)
Creates a new buffer that is a deep copy of the remaining bytes in the given buffer (between index buf.position() and buf.limit()); leaves the src buffer unmodified. |
static void |
copy(ByteBuffer src,
int srcPos,
ByteBuffer dest,
int destPos,
int length)
The buffer equivalent of System.arraycopy(java.lang.Object, int, java.lang.Object, int, int) ;
copies src[srcPos]..src[srcPos+length-1] to dest[destPos]..dest[destPos+length-1],
leaving the mark, position and limit of both src and dest unmodified;
Behaves as expected even if src==dest. |
static ByteBuffer |
ensureCapacity(ByteBuffer buffer,
int minCapacity)
Ensures that a given buffer can hold up to minCapacity bytes. |
static String |
getString(ByteBuffer buffer,
Charset charset)
Returns a string holding a decoded representation of the remaining bytes in the given buffer (relative bulk operation). |
static boolean |
hasMark(Buffer buffer)
Returns whether or not a given buffer has the mark defined. |
static void |
putString(ByteBuffer buffer,
String str,
Charset charset)
Fills the bytes of the encoded string into the given buffer (relative bulk operation). |
static byte[] |
toByteArray(ByteBuffer src)
Creates and returns a byte array filled with the remaining bytes of given buffer (between index buf.position() and buf.limit()); leaves the src buffer unmodified. |
static byte[] |
toByteArray(String str,
Charset charset)
Returns a byte array holding the encoded bytes of the given string. |
static ByteBuffer |
toByteBuffer(String str,
Charset charset)
Returns a bytebuffer holding the encoded bytes of the given string. |
static String |
toString(byte[] bytes,
Charset charset)
Returns a decoded string representation of the given bytes. |
static String |
toString(byte[] bytes,
int offset,
int length,
Charset charset)
Returns a decoded string representation of the given bytes. |
static String |
toString(ByteBuffer buffer,
Charset charset)
Returns a decoded string representation of the bytes in the given buffer; leaves the buffer unmodified. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static ByteBuffer ensureCapacity(ByteBuffer buffer, int minCapacity)
minCapacity
- the desired minimum capacity.public static ByteBuffer concat(ByteBuffer[] buffers)
buffers
- -
the buffers to concatenate
public static void copy(ByteBuffer src, int srcPos, ByteBuffer dest, int destPos, int length)
System.arraycopy(java.lang.Object, int, java.lang.Object, int, int)
;
copies src[srcPos]..src[srcPos+length-1] to dest[destPos]..dest[destPos+length-1],
leaving the mark, position and limit of both src and dest unmodified;
Behaves as expected even if src==dest.
src
- the buffer to read fromsrcPos
- the index of the first byte to readdest
- the buffer to write todestPos
- the index of the first byte to writelength
- the number of bytes to copypublic static ByteBuffer copy(ByteBuffer src)
src
- the buffer to copy
public static String getString(ByteBuffer buffer, Charset charset)
buffer
- the buffer to convert.charset
- the requested charset to convert with
(e.g. Charset.forName("US-ASCII"), Charset.forName("UTF-8"))
public static boolean hasMark(Buffer buffer)
buffer
- the buffer to check
public static void putString(ByteBuffer buffer, String str, Charset charset)
buffer
- the buffer to fill into.str
- the string to convert.charset
- the requested charset to convert with
(e.g. Charset.forName("US-ASCII"), Charset.forName("UTF-8"))public static byte[] toByteArray(ByteBuffer src)
src
- the bytebuffer to read from
public static ByteBuffer toByteBuffer(String str, Charset charset)
str
- the string to convert.charset
- the requested charset to convert with
(e.g. Charset.forName("US-ASCII"), Charset.forName("UTF-8"))
public static byte[] toByteArray(String str, Charset charset)
str
- the string to convert.charset
- the requested charset to convert with
(e.g. Charset.forName("US-ASCII"), Charset.forName("UTF-8"))
public static String toString(ByteBuffer buffer, Charset charset)
buffer
- the buffer to convertcharset
- the requested charset to convert with
(e.g. Charset.forName("US-ASCII"), Charset.forName("UTF-8"))
public static String toString(byte[] bytes, int offset, int length, Charset charset)
bytes
- the bytes to convertoffset
- The offset of the subarray to be used; must be non-negative
and no larger than bytes.length
- The length of the subarray to be used; must be non-negative
and no larger than bytes.length - offset.charset
- the requested charset to convert with (e.g.
Charset.forName("US-ASCII"), Charset.forName("UTF-8"))
public static String toString(byte[] bytes, Charset charset)
bytes
- the bytes to convertcharset
- the requested charset to convert with
(e.g. Charset.forName("US-ASCII"), Charset.forName("UTF-8"))
|
Sea 0.2.2 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |