List of utility methods to do ByteBuffer from
ByteBuffer | getByteBufferByString(String message) get Byte Buffer By String ByteBuffer result = ByteBuffer.allocate(message.length());
result.put(message.getBytes());
result.flip();
return result;
|
ByteBuffer | getByteBufferFromBytes(byte[] data) ByteBuffer from byte array return ByteBuffer.wrap(data);
|
ByteBuffer | getByteBufferFromInt(int value) ByteBuffer from long return ByteBuffer.wrap(getBytesFromInt(value));
|
ByteBuffer | getByteBufferFromList(List ByteBuffer from list return ByteBuffer.wrap(getBytesFromList(values));
|
ByteBuffer | getByteBufferFromUTF8(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; ... |
ByteBuffer | getByteBufferFromUUID(java.util.UUID uuid) ByteBuffer from UUID return ByteBuffer.wrap(getBytesFromUUID(uuid));
|
OutputStream | getByteBufferOutputStream(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); }; ... |
Method | getByteBufferReadMethod(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); |
Collection | getByteBuffers(Collection 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; |
ByteBuffer | getByteBufferUtf8(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"); |