ByteBufferSupport { public static void addByteBuffers(List<ByteBuffer> list, ByteArrayOutputStream bytes) throws IOException { if (CollectionUtils.isNotEmpty(list)) { bytes.write(toIntBytes(list.size())); for (ByteBuffer bb : list) { addByteBuffer(bb, bytes); } } else { bytes.write(toIntBytes(0)); } }  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 testNonEmptyAddByteBufferList() throws Exception { ByteBuffer bb = getByteBuffer(BYTE_ARRAY); ByteBuffer bbTwo = getByteBuffer(BYTE_ARRAY); ByteArrayOutputStream stream = new ByteArrayOutputStream(); List<ByteBuffer> bList = Lists.newArrayList(bb, bbTwo); ByteBufferSupport.addByteBuffers(bList, stream); assertEquals(44, stream.size()); }