ByteBufferSupport { public static void addByteBuffer(ByteBuffer bb, ByteArrayOutputStream bytes) throws IOException { if (byteBufferNotEmpty(bb)) { bytes.write(toIntBytes(bb.array().length)); bytes.write(bb.array()); } }  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 testNonEmptyAddByteBuffer() throws Exception { ByteBuffer bb = getByteBuffer(BYTE_ARRAY); ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteBufferSupport.addByteBuffer(bb, stream); assertEquals(20, stream.size()); ByteBufferSupport.addByteBuffer(bb, stream); assertEquals(40, stream.size()); }
@Test public void testEmptyAddByteBuffer() throws Exception { ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteBuffer bb = getByteBuffer(ArrayUtils.EMPTY_BYTE_ARRAY); ByteBufferSupport.addByteBuffer(bb, stream); assertEquals(0, stream.size()); }
@Test public void testNullAddByteBuffer() throws Exception { ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteBufferSupport.addByteBuffer(null, stream); assertEquals(0, stream.size()); }