Java Utililty Methods ByteBuffer from

List of utility methods to do ByteBuffer from

Description

The list of methods to do ByteBuffer from are organized into topic(s).

Method

ByteBuffergetByteBuffer(byte[] array)
This method convert byte array to ByteBuffer object.
ByteBuffer bb = null;
if (array != null) {
    bb = ByteBuffer.wrap(array);
return bb;
ByteBuffergetByteBuffer(byte[] data, int fromByte, int length)
get Byte Buffer
return ByteBuffer.wrap(getByteArray(data, fromByte, length).toByteArray());
ByteBuffergetByteBuffer(ByteBuffer source, int count)
Please note that this moves the source buffer forward.
byte[] data = new byte[count];
source.get(data);
ByteBuffer result = ByteBuffer.wrap(data);
result.order(source.order());
return result;
ByteBuffergetByteBuffer(final String string, final Charset charset)
Calls String#getBytes(Charset)
if (string == null) {
    return null;
return ByteBuffer.wrap(string.getBytes(charset));
ByteBuffergetByteBuffer(int size)
Returns a fully initialized empty ByteBuffer in little endian order.
return ByteBuffer.allocate(Math.max(0, size)).order(ByteOrder.LITTLE_ENDIAN);
ByteBuffergetByteBuffer(Object obj)
Gets the byte buffer.
byte[] bytes = getBytes(obj);
ByteBuffer buff = ByteBuffer.wrap(bytes);
return buff;
ByteBuffergetByteBuffer(String base64)
Gets a byte buffer corresponding to the base64 string given.
byte[] binary = BinaryUtils.fromBase64(base64);
return ByteBuffer.wrap(binary);
ByteBuffergetByteBuffer(String filePath, int start, long size)
get Byte Buffer
File binaryFile = new File(filePath);
FileChannel binaryFileChannel = new RandomAccessFile(binaryFile, "r").getChannel();
return binaryFileChannel.map(FileChannel.MapMode.READ_ONLY, start, size);
byte[]getByteBufferArray(ByteBuffer byteBuffer)
get Byte Buffer Array
if (byteBuffer.hasArray()) {
    byte[] buf = new byte[byteBuffer.limit()];
    System.arraycopy(byteBuffer.array(), byteBuffer.arrayOffset(), buf, 0, buf.length);
    return buf;
byte[] buf = new byte[byteBuffer.limit()];
int pos = byteBuffer.position();
byteBuffer.position(0);
...
StringgetByteBufferAsString(ByteBuffer buff)
get Byte Buffer As String
int pos = buff.position();
byte[] tmpBuff = new byte[buff.remaining()];
buff.get(tmpBuff);
buff.position(pos);
return new String(tmpBuff, Charset.forName("US-ASCII"));