public class ByteBufferUtils extends Object
Modifier and Type | Method and Description |
---|---|
static ByteBuffer |
allocate(int capacity,
boolean direct)
Allocate ByteBuffer.
|
static String |
charsetToString(int charset) |
static byte[] |
extractByteArray(ByteBuffer buf) |
static byte[] |
extractByteArrayLen(ByteBuffer buf,
int len) |
static byte[] |
extractByteString(ByteBuffer buf) |
static String |
extractShortString(ByteBuffer buf) |
static String |
extractString(ByteBuffer buf) |
static String |
extractStringWithCharset(ByteBuffer buf) |
static long |
extractUInt(ByteBuffer buf) |
static int |
extractUShort(ByteBuffer buf) |
static ByteBuffer |
gather(ByteBuffer[] buffers)
Gather ByteBuffers to one ByteBuffer.
|
static boolean |
hasRemaining(ByteBuffer[] buffers)
Judge ByteBuffers have remaining bytes.
|
static ByteBuffer |
increaseCapacity(ByteBuffer buffer,
int size)
Increase ByteBuffer's capacity.
|
static int |
indexOf(ByteBuffer buffer,
ByteBuffer pattern)
Returns the index within this buffer of the first occurrence of the
specified pattern buffer.
|
static void |
insertByteArray(byte[] array,
ByteBuffer buf) |
static void |
insertByteArray(byte[] value,
int len,
ByteBuffer buf) |
static void |
insertByteString(byte[] array,
ByteBuffer buf) |
static void |
insertString(String str,
ByteBuffer buf) |
static void |
insertStringWithCharset(byte[] str,
int charset,
ByteBuffer buf) |
static void |
insertUInt(long value,
ByteBuffer buf) |
static int |
lengthOfByteArray(byte[] array) |
static int |
lengthOfByteString(byte[] array) |
static int |
lengthOfString(String str) |
static int |
lengthOfStringWithCharset(byte[] array) |
static void |
printBBInfo(ByteBuffer buf) |
static void |
toHexString(String header,
ByteBuffer buf) |
static void |
toHexString(String header,
ByteBuffer buf,
int length) |
public static ByteBuffer allocate(int capacity, boolean direct) throws IllegalArgumentException
capacity
- ByteBuffer capacitydirect
- allocate DirectByteBufferIllegalArgumentException
- if capacity is negativepublic static ByteBuffer increaseCapacity(ByteBuffer buffer, int size) throws IllegalArgumentException
buffer
- the ByteBuffer want to increase capacitysize
- increased sizeIllegalArgumentException
- if size less than 0 or buffer is nullpublic static ByteBuffer gather(ByteBuffer[] buffers)
buffers
- ByteBufferspublic static boolean hasRemaining(ByteBuffer[] buffers)
buffers
- ByteBufferspublic static int indexOf(ByteBuffer buffer, ByteBuffer pattern)
buffer
- the bufferpattern
- the pattern bufferpublic static void toHexString(String header, ByteBuffer buf)
public static void toHexString(String header, ByteBuffer buf, int length)
public static String extractString(ByteBuffer buf) throws UnsupportedEncodingException
UnsupportedEncodingException
public static String extractStringWithCharset(ByteBuffer buf) throws UnsupportedEncodingException
UnsupportedEncodingException
public static byte[] extractByteString(ByteBuffer buf)
public static byte[] extractByteArray(ByteBuffer buf)
public static int extractUShort(ByteBuffer buf)
public static long extractUInt(ByteBuffer buf)
public static byte[] extractByteArrayLen(ByteBuffer buf, int len)
public static String extractShortString(ByteBuffer buf) throws UnsupportedEncodingException
UnsupportedEncodingException
public static void insertString(String str, ByteBuffer buf) throws UnsupportedEncodingException
UnsupportedEncodingException
public static void insertByteString(byte[] array, ByteBuffer buf) throws UnsupportedEncodingException
UnsupportedEncodingException
public static void insertStringWithCharset(byte[] str, int charset, ByteBuffer buf) throws UnsupportedEncodingException
UnsupportedEncodingException
public static void insertByteArray(byte[] array, ByteBuffer buf)
public static void insertByteArray(byte[] value, int len, ByteBuffer buf)
public static void insertUInt(long value, ByteBuffer buf)
public static int lengthOfString(String str)
public static int lengthOfByteString(byte[] array)
public static int lengthOfStringWithCharset(byte[] array)
public static int lengthOfByteArray(byte[] array)
public static void printBBInfo(ByteBuffer buf)
public static String charsetToString(int charset)
Copyright © 2016. All rights reserved.