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

ByteBuffergetByteBufferByString(String message)
get Byte Buffer By String
ByteBuffer result = ByteBuffer.allocate(message.length());
result.put(message.getBytes());
result.flip();
return result;
ByteBuffergetByteBufferFromBytes(byte[] data)
ByteBuffer from byte array
return ByteBuffer.wrap(data);
ByteBuffergetByteBufferFromInt(int value)
ByteBuffer from long
return ByteBuffer.wrap(getBytesFromInt(value));
ByteBuffergetByteBufferFromList(List values)
ByteBuffer from list
return ByteBuffer.wrap(getBytesFromList(values));
ByteBuffergetByteBufferFromUTF8(String str)
get Byte Buffer From UTF
Charset charset = Charset.forName("UTF-8");
CharsetEncoder encoder = charset.newEncoder();
try {
    return encoder.encode(CharBuffer.wrap(str));
} catch (Exception e) {
    e.printStackTrace();
return null;
...
ByteBuffergetByteBufferFromUUID(java.util.UUID uuid)
ByteBuffer from UUID
return ByteBuffer.wrap(getBytesFromUUID(uuid));
OutputStreamgetByteBufferOutputStream(final ByteBuffer buf)
Create an OutputStream for a ByteBuffer
return new OutputStream() {
    public void write(int b) throws IOException {
        buf.put((byte) b);
    public void write(byte[] bytes, int off, int len) throws IOException {
        buf.put(bytes, off, len);
};
...
MethodgetByteBufferReadMethod(Class clazz)
Uses reflection to find the correct java.nio.ByteBuffer "absolute get" method for a given primitive type.
assert clazz.isPrimitive();
return primitiveToByteBufferReadMethod.get(clazz);
CollectiongetByteBuffers(Collection newValue)
Returns a list of ByteBuffers corresponding to the base64 strings given.
List<ByteBuffer> buffers = new LinkedList<ByteBuffer>();
for (String value : newValue) {
    buffers.add(getByteBuffer(value));
return buffers;
ByteBuffergetByteBufferUtf8(final String string)
Encodes the given string into a byte buffer using the UTF-8 charset, storing the result into a new byte array.
return getByteBuffer(string, "UTF-8");