List of utility methods to do ByteBuffer Capacity
ByteBuffer | leByteBuffer(int capacity) le Byte Buffer byte[] underlying = new byte[capacity]; return ByteBuffer.wrap(underlying).order(ByteOrder.LITTLE_ENDIAN); |
ByteBuffer | nativeByteBuffer(int capacity) native Byte Buffer ByteBuffer buffer = ByteBuffer.allocateDirect(capacity);
buffer.order(ByteOrder.nativeOrder());
return buffer;
|
ByteBuffer | newByteBuffer(int margin, int capacity) new Byte Buffer ByteBuffer b = ByteBuffer.wrap(new byte[margin + capacity]); b.position(margin); b.mark(); return b; |
ByteBuffer | parseToByteBuffer(int capacity, String value) parse To Byte Buffer ByteBuffer buffer = ByteBuffer.allocate(capacity);
buffer.rewind();
buffer.put(value.getBytes());
buffer.rewind();
return buffer;
|
ByteBuffer | resetAddressAndCapacity(final ByteBuffer byteBuffer, final long address, final int capacity) Set the private address of direct ByteBuffer . if (!byteBuffer.isDirect()) { throw new IllegalArgumentException("Can only change address of direct buffers"); try { final Field addressField = Buffer.class.getDeclaredField("address"); addressField.setAccessible(true); addressField.set(byteBuffer, Long.valueOf(address)); final Field capacityField = Buffer.class.getDeclaredField("capacity"); ... |