public class NIOUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
cancelKeySilently(java.nio.channels.SelectionKey key)
Silently cancel a key.
|
static void |
closeChannelSilently(java.nio.channels.Channel channel)
Silently close a channel.
|
static void |
closeKeyAndChannelSilently(java.nio.channels.SelectionKey key,
java.nio.channels.Channel channel)
Silently close both a key and a channel.
|
static java.nio.ByteBuffer[] |
compact(java.nio.ByteBuffer[] buffers)
Compacts an array of byte buffers, retaining only the buffers that have remaining data.
|
static java.nio.ByteBuffer[] |
concat(java.nio.ByteBuffer[] buffers,
java.nio.ByteBuffer buffer) |
static java.nio.ByteBuffer[] |
concat(java.nio.ByteBuffer[] buffers1,
java.nio.ByteBuffer[] buffers2) |
static java.nio.ByteBuffer[] |
concat(java.nio.ByteBuffer buffer,
java.nio.ByteBuffer[] buffers2) |
static java.nio.ByteBuffer |
copy(java.nio.ByteBuffer buffer) |
static int |
getPacketSizeFromByteArray(byte[] data,
int length,
boolean bigEndian)
Converts a value in a header byte array encoded in either big or little endian
encoding.
|
static int |
getPacketSizeFromByteBuffer(java.nio.ByteBuffer header,
int size,
boolean bigEndian)
Converts a value in a header buffer encoded in either big or little endian
encoding.
|
static boolean |
isEmpty(java.nio.ByteBuffer[] byteBuffers) |
static java.nio.ByteBuffer |
join(java.nio.ByteBuffer buffer1,
java.nio.ByteBuffer buffer2) |
static long |
remaining(java.nio.ByteBuffer[] byteBuffers) |
static void |
setHeaderForPacketSize(byte[] buffer,
int headerSize,
int valueToEncode,
boolean bigEndian)
Inserts a header in the first bytes of a byte array
in either big or little endian encoding (i.e.
|
static void |
setPacketSizeInByteBuffer(java.nio.ByteBuffer byteBuffer,
int headerSize,
int valueToEncode,
boolean bigEndian)
Encodes a length into byte buffer using
either big or little endian encoding (i.e.
|
public static void closeKeyAndChannelSilently(java.nio.channels.SelectionKey key,
java.nio.channels.Channel channel)
key - the key to cancel, may be null.channel - the channel to close, may be null.public static void setPacketSizeInByteBuffer(java.nio.ByteBuffer byteBuffer,
int headerSize,
int valueToEncode,
boolean bigEndian)
byteBuffer - the ByteBuffer to use.headerSize - the header size in bytes. 1-4.valueToEncode - the value to encode, 0 <= value < 2^(headerSize * 8)bigEndian - if the encoding is big endian or not.java.lang.IllegalArgumentException - if the value is out of range for the given header size.public static void setHeaderForPacketSize(byte[] buffer,
int headerSize,
int valueToEncode,
boolean bigEndian)
buffer - the byte array to set the header forheaderSize - the header size in bytes. 1-4.valueToEncode - the value to encode, 0 <= value < 2^(headerSize * 8)bigEndian - if the encoding is big endian or not.java.lang.IllegalArgumentException - if the value is out of range for the given header size.public static int getPacketSizeFromByteBuffer(java.nio.ByteBuffer header,
int size,
boolean bigEndian)
Note that trying to decode a value larger than 2^31 - 2 is not supported.
header - the header to encode from.size - the header size, 1-4.bigEndian - if the encoding is big endian or not.public static int getPacketSizeFromByteArray(byte[] data,
int length,
boolean bigEndian)
Note that trying to decode a value larger than 2^31 - 2 is not supported.
data - the data to encode from.length - the length of the header.bigEndian - if the encoding is big endian or not.public static void closeChannelSilently(java.nio.channels.Channel channel)
channel - the channel to close, may be null.public static void cancelKeySilently(java.nio.channels.SelectionKey key)
key - the key to cancel, may be null.public static java.nio.ByteBuffer[] compact(java.nio.ByteBuffer[] buffers)
buffers - the buffers to compact.public static java.nio.ByteBuffer[] concat(java.nio.ByteBuffer[] buffers,
java.nio.ByteBuffer buffer)
public static java.nio.ByteBuffer[] concat(java.nio.ByteBuffer buffer,
java.nio.ByteBuffer[] buffers2)
public static java.nio.ByteBuffer[] concat(java.nio.ByteBuffer[] buffers1,
java.nio.ByteBuffer[] buffers2)
public static java.nio.ByteBuffer copy(java.nio.ByteBuffer buffer)
public static long remaining(java.nio.ByteBuffer[] byteBuffers)
public static boolean isEmpty(java.nio.ByteBuffer[] byteBuffers)
public static java.nio.ByteBuffer join(java.nio.ByteBuffer buffer1,
java.nio.ByteBuffer buffer2)