The list of methods to do ByteBuffer from are organized into topic(s).
ByteBuffer
getByteBuffer(byte[] array) This method convert byte array to ByteBuffer object.
ByteBuffer bb = null;
if (array != null) {
bb = ByteBuffer.wrap(array);
return bb;
ByteBuffer
getByteBuffer(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;
ByteBuffer
getByteBuffer(int size) Returns a fully initialized empty ByteBuffer in little endian order.
return ByteBuffer.allocate(Math.max(0, size)).order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer
getByteBuffer(Object obj) Gets the byte buffer.
byte[] bytes = getBytes(obj);
ByteBuffer buff = ByteBuffer.wrap(bytes);
return buff;
ByteBuffer
getByteBuffer(String base64) Gets a byte buffer corresponding to the base64 string given.
byte[] binary = BinaryUtils.fromBase64(base64);
return ByteBuffer.wrap(binary);
ByteBuffer
getByteBuffer(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);
...
String
getByteBufferAsString(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"));