ByteBufferSupport { public static byte[] getBytes(ByteBuffer bb, int size) { byte bytes[] = new byte[size]; bb.get(bytes); return bytes; }  static void addByteBuffers(List<ByteBuffer> list, ByteArrayOutputStream bytes); static void addByteBuffer(ByteBuffer bb, ByteArrayOutputStream bytes); static ByteBuffer toByteBuffer(Protos.TaskID taskId); static ByteBuffer toByteBuffer(Protos.FrameworkID frameworkId); static ByteBuffer toBuffer(GeneratedMessageV3 message); static byte[] toIntBytes(int src); static ByteBuffer toByteBuffer(NodeTask nt); static Protos.TaskID toTaskId(ByteBuffer bb); static Protos.FrameworkID toFrameworkID(ByteBuffer bb); static NodeTask toNodeTask(ByteBuffer bb); static byte[] getTaskBytes(NodeTask nt); static byte[] getExecutorInfoBytes(NodeTask nt); static byte[] getSlaveBytes(NodeTask nt); static void putBytes(ByteBuffer bb, byte bytes[]); static byte[] getBytes(ByteBuffer bb, int size); static String toString(ByteBuffer bb); static byte[] toBytes(String s); static ServiceResourceProfile getServiceResourceProfile(ByteBuffer bb); static Constraint getConstraint(ByteBuffer bb); static Protos.SlaveID toSlaveId(ByteBuffer bb); static Protos.TaskStatus toTaskStatus(ByteBuffer bb); static Protos.ExecutorInfo toExecutorInfo(ByteBuffer bb); static ByteBuffer fillBuffer(byte src[]); static List<ByteBuffer> createBufferList(ByteBuffer bb, int size); static ByteBuffer createBuffer(ByteBuffer bb); static final int INT_SIZE; static final String UTF8; static final byte[] ZERO_BYTES; }
@Test public void testGetBytes() throws Exception { ByteBuffer bb = getByteBuffer(BYTE_ARRAY); byte[] bytes = ByteBufferSupport.getBytes(bb, bb.capacity()); assertEquals(BYTE_ARRAY.length, bytes.length); for (int i = 0, j = bytes.length; i < j; i++) { assertEquals(bytes[i], BYTE_ARRAY[i]); } }