Code example for ByteArrayOutputStream

Methods: toByteArray

0
 
  private static long OFFSET_IN_BLOCK = 12345L;
  private static int SEQNO = 54321;
 
  private byte[] prepareFakePacket(byte[] data, byte[] sums) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
     
    int packetLen = data.length + sums.length + 4;
    PacketHeader header = new PacketHeader(
        packetLen, OFFSET_IN_BLOCK, SEQNO, false, data.length, false);
    header.write(dos);
     
    dos.write(sums);
    dos.write(data);
    dos.flush();
    return baos.toByteArray();
  } 
   
  private static byte[] remainingAsArray(ByteBuffer buf) {
    byte[] b = new byte[buf.remaining()];
    buf.get(b);
Contextual code suggestions in your IDE  Get Codota for Java