@Test public void toByteArrayAndBack() throws Exception { byte[] arrayA = peerList.toByteArray(); byte[] arrayB; arrayB = new PeerList(arrayA).toByteArray(); assertArrayEquals("The two arrays differ!", arrayA, arrayB); }
@Override public byte[] toByteArray() { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(arrayOutputStream); try { writeHeader(dataStream); dataStream.writeShort(peers.size()); for (Destination peer: peers) dataStream.write(peer.toByteArray(), 0, 384); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return arrayOutputStream.toByteArray(); }
PeerList extends DataPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(arrayOutputStream); try { writeHeader(dataStream); dataStream.writeShort(peers.size()); for (Destination peer: peers) dataStream.write(peer.toByteArray(), 0, 384); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return arrayOutputStream.toByteArray(); } }
PeerList extends DataPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(arrayOutputStream); try { writeHeader(dataStream); dataStream.writeShort(peers.size()); for (Destination peer: peers) dataStream.write(peer.toByteArray(), 0, 384); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return arrayOutputStream.toByteArray(); } PeerList(Collection<Destination> peers);  PeerList(byte[] data); }
PeerList extends DataPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(arrayOutputStream); try { writeHeader(dataStream); dataStream.writeShort(peers.size()); for (Destination peer: peers) dataStream.write(peer.toByteArray(), 0, 384); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return arrayOutputStream.toByteArray(); } PeerList(Collection<Destination> peers);  PeerList(byte[] data); Collection<Destination> getPeers(); @Override byte[] toByteArray(); }
PeerList extends DataPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(arrayOutputStream); try { writeHeader(dataStream); dataStream.writeShort(peers.size()); for (Destination peer: peers) dataStream.write(peer.toByteArray(), 0, 384); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return arrayOutputStream.toByteArray(); } PeerList(Collection<Destination> peers);  PeerList(byte[] data); Collection<Destination> getPeers(); @Override byte[] toByteArray();  }