@Test public void toByteArrayAndBack() { int size = 10000; ByteBuffer buffer = ByteBuffer.allocate(size + 2); buffer.put((byte)(size >> 8)); buffer.put((byte)size); for (int i=0; i<size; i++) buffer.put((byte)i); buffer.rewind(); ReturnChain returnChain = new ReturnChain(buffer); assertTrue(buffer.hasArray()); byte[] arrayA = buffer.array(); byte[] arrayB = returnChain.toByteArray(); assertArrayEquals("The two arrays differ!", arrayA, arrayB); }
public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); try { writeTo(byteStream); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteStream.toByteArray(); }
ReturnChain { public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); try { writeTo(byteStream); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteStream.toByteArray(); } }
ReturnChain { public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); try { writeTo(byteStream); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteStream.toByteArray(); } ReturnChain();  ReturnChain(ByteBuffer input); }
ReturnChain { public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); try { writeTo(byteStream); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteStream.toByteArray(); } ReturnChain();  ReturnChain(ByteBuffer input); void writeTo(OutputStream output); byte[] toByteArray(); }
ReturnChain { public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); try { writeTo(byteStream); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteStream.toByteArray(); } ReturnChain();  ReturnChain(ByteBuffer input); void writeTo(OutputStream output); byte[] toByteArray();  }