RequestPacket extends NetworkPacket { public static RequestPacket[] createPackets( final int net, final NodeAddress src, final NodeAddress dst, final byte id, final byte[] buf) { int i; if (buf.length > REQUEST_PAYLOAD_SIZE) { i = 2; } else { i = 1; } int remaining = buf.length % REQUEST_PAYLOAD_SIZE; RequestPacket[] ll = new RequestPacket[i]; byte[] payload; if (i == 1) { payload = new byte[remaining]; } else { payload = new byte[REQUEST_PAYLOAD_SIZE]; } System.arraycopy(buf, 0, payload, 0, payload.length); RequestPacket np = new RequestPacket(net, src, dst, id, 0, i, payload); ll[0] = np; if (i > 1) { payload = new byte[remaining]; System.arraycopy(buf, REQUEST_PAYLOAD_SIZE, payload, 0, remaining); np = new RequestPacket(net, src, dst, id, 1, i, payload); ll[1] = np; } return ll; } RequestPacket(final byte[] data);  RequestPacket(final NetworkPacket data);  RequestPacket(final int[] data); private  RequestPacket(final int net,
            final NodeAddress src,
            final NodeAddress dst,
            final int id,
            final int part,
            final int total,
            final byte[] data); static RequestPacket[] createPackets(
            final int net,
            final NodeAddress src,
            final NodeAddress dst,
            final byte id,
            final byte[] buf); static NetworkPacket mergePackets(final RequestPacket rp0,
            final RequestPacket rp1); final byte[] getData(); final int getDataSize(); final int getId(); final int getPart(); final int getTotal();  }
@Test public void testToByteArray() { DataPacket dp = new DataPacket(1, new NodeAddress("0.2"), new NodeAddress("0.0"), ("SDN-WISE: The stateful Software Defined Networking solution" + " for the Internet of Things - Test.").getBytes(UTF8_CHARSET) ); RequestPacket[] instance = RequestPacket.createPackets(1, new NodeAddress("0.1"), new NodeAddress("0.1"), (byte) 1, dp.toByteArray()); String expResult = "[1, 116, 0, 1, 0, 1, 3, 100, 0, 0, 1, 0, 2, 1, 104," + " 0, 0, 0, 2, 0, 100, 0, 0, 83, 68, 78, 45, 87, 73, 83, 69," + " 58, 32, 84, 104, 101, 32, 115, 116, 97, 116, 101, 102, 117," + " 108, 32, 83, 111, 102, 116, 119, 97, 114, 101, 32, 68, 101," + " 102, 105, 110, 101, 100, 32, 78, 101, 116, 119, 111, 114," + " 107, 105, 110, 103, 32, 115, 111, 108, 117, 116, 105, 111," + " 110, 32, 102, 111, 114, 32, 116, 104, 101, 32, 73, 110," + " 116, 101, 114, 110, 101, 116, 32, 111, 102, 32, 84, 104," + " 105, 110, 103, 115, 32, 45, 32, 84, 101, 115, 116][1, 14," + " 0, 1, 0, 1, 3, 100, 0, 0, 1, 1, 2, 46]"; StringBuilder sb = new StringBuilder(); for (RequestPacket rp : instance) { sb.append(Arrays.toString(rp.toByteArray())); } assertEquals(expResult, sb.toString()); }