ByteBufferSupport { public static String toString(ByteBuffer bb) { byte[] bytes = new byte[bb.getInt()]; String s = ""; try { if (ArrayUtils.isNotEmpty(bytes)) { bb.get(bytes); s = new String(bytes, UTF8); } } catch (Exception e) { throw new RuntimeException("ByteBuffer not in expected format," + " failed to parse string bytes", e); } return s; }  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 testToString() throws Exception { String output = ByteBufferSupport.toString(ByteBufferSupport.toByteBuffer(task)); assertTrue(output.contains("\"name\":\"profile\"")); assertTrue(output.contains("\"cpus\":0.1")); assertTrue(output.contains("\"memory\":1024.0")); assertTrue(output.contains("\"executorCpu\":0.0")); assertTrue(output.contains("\"executorMemory\":0.0")); assertTrue(output.contains("\"className\":\"org.apache.myriad.scheduler.ServiceResourceProfile\"")); }