@Test public void toByteArrayAndBack() throws Exception { byte[] arrayA = storeRequest.toByteArray(); byte[] arrayB = new StoreRequest(arrayA).toByteArray(); assertArrayEquals("The two arrays differ!", arrayA, arrayB); }
@Override public byte[] toByteArray() { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteArrayStream); try { writeHeader(dataStream); String hashCashString = hashCash.toString(); dataStream.writeShort(hashCashString.length()); dataStream.write(hashCashString.getBytes()); byte[] dataToStore = packetToStore.toByteArray(); dataStream.writeShort(dataToStore.length); dataStream.write(dataToStore); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); }
StoreRequest extends CommunicationPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteArrayStream); try { writeHeader(dataStream); String hashCashString = hashCash.toString(); dataStream.writeShort(hashCashString.length()); dataStream.write(hashCashString.getBytes()); byte[] dataToStore = packetToStore.toByteArray(); dataStream.writeShort(dataToStore.length); dataStream.write(dataToStore); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } }
StoreRequest extends CommunicationPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteArrayStream); try { writeHeader(dataStream); String hashCashString = hashCash.toString(); dataStream.writeShort(hashCashString.length()); dataStream.write(hashCashString.getBytes()); byte[] dataToStore = packetToStore.toByteArray(); dataStream.writeShort(dataToStore.length); dataStream.write(dataToStore); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } StoreRequest(DhtStorablePacket packetToStore);  StoreRequest(byte[] data); }
StoreRequest extends CommunicationPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteArrayStream); try { writeHeader(dataStream); String hashCashString = hashCash.toString(); dataStream.writeShort(hashCashString.length()); dataStream.write(hashCashString.getBytes()); byte[] dataToStore = packetToStore.toByteArray(); dataStream.writeShort(dataToStore.length); dataStream.write(dataToStore); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } StoreRequest(DhtStorablePacket packetToStore);  StoreRequest(byte[] data); Hash getKey(); DhtStorablePacket getPacketToStore(); @Override byte[] toByteArray(); @Override String toString(); }
StoreRequest extends CommunicationPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteArrayStream); try { writeHeader(dataStream); String hashCashString = hashCash.toString(); dataStream.writeShort(hashCashString.length()); dataStream.write(hashCashString.getBytes()); byte[] dataToStore = packetToStore.toByteArray(); dataStream.writeShort(dataToStore.length); dataStream.write(dataToStore); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } StoreRequest(DhtStorablePacket packetToStore);  StoreRequest(byte[] data); Hash getKey(); DhtStorablePacket getPacketToStore(); @Override byte[] toByteArray(); @Override String toString();  }