@Test public void toByteArrayAndBack() throws DataFormatException, MalformedPacketException { byte[] bytes, bytes2; bytes = relayRequestSingle.toByteArray(); bytes2 = new RelayRequest(bytes).toByteArray(); assertArrayEquals("The two packets differ!", bytes, bytes2); bytes = relayRequestMulti.toByteArray(); bytes2 = new RelayRequest(bytes).toByteArray(); assertArrayEquals("The two packets differ!", bytes, bytes2); }
@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()); dataStream.writeInt((int)(delayMilliseconds/1000)); dataStream.write(nextDestination.toByteArray(), 0, 384); returnChain.writeTo(dataStream); dataStream.writeShort(payload.length); dataStream.write(payload); byte[] padding = new byte[padBytes]; dataStream.write(padding); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); }
RelayRequest 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()); dataStream.writeInt((int)(delayMilliseconds/1000)); dataStream.write(nextDestination.toByteArray(), 0, 384); returnChain.writeTo(dataStream); dataStream.writeShort(payload.length); dataStream.write(payload); byte[] padding = new byte[padBytes]; dataStream.write(padding); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } }
RelayRequest 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()); dataStream.writeInt((int)(delayMilliseconds/1000)); dataStream.write(nextDestination.toByteArray(), 0, 384); returnChain.writeTo(dataStream); dataStream.writeShort(payload.length); dataStream.write(payload); byte[] padding = new byte[padBytes]; dataStream.write(padding); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } RelayRequest(CommunicationPacket payload, Destination nextDestination, long delayMilliseconds, int padBytes);  RelayRequest(CommunicationPacket payload, Destination nextDestination, long delayMilliseconds, ReturnChain returnChain);  RelayRequest(byte[] data); }
RelayRequest 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()); dataStream.writeInt((int)(delayMilliseconds/1000)); dataStream.write(nextDestination.toByteArray(), 0, 384); returnChain.writeTo(dataStream); dataStream.writeShort(payload.length); dataStream.write(payload); byte[] padding = new byte[padBytes]; dataStream.write(padding); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } RelayRequest(CommunicationPacket payload, Destination nextDestination, long delayMilliseconds, int padBytes);  RelayRequest(CommunicationPacket payload, Destination nextDestination, long delayMilliseconds, ReturnChain returnChain);  RelayRequest(byte[] data); static RelayRequest create(CommunicationPacket payload, RelayPeerManager peerManager, int numHops, long minDelay, long maxDelay); static int getMaxOverhead(int numHops); Destination getNextDestination(); long getDelay(); void setSendTime(long sendTime); long getSendTime(); HashCash getHashCash(); byte[] getPayload(); CommunicationPacket getStoredPacket(I2PSession i2pSession); @Override byte[] toByteArray(); }
RelayRequest 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()); dataStream.writeInt((int)(delayMilliseconds/1000)); dataStream.write(nextDestination.toByteArray(), 0, 384); returnChain.writeTo(dataStream); dataStream.writeShort(payload.length); dataStream.write(payload); byte[] padding = new byte[padBytes]; dataStream.write(padding); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } RelayRequest(CommunicationPacket payload, Destination nextDestination, long delayMilliseconds, int padBytes);  RelayRequest(CommunicationPacket payload, Destination nextDestination, long delayMilliseconds, ReturnChain returnChain);  RelayRequest(byte[] data); static RelayRequest create(CommunicationPacket payload, RelayPeerManager peerManager, int numHops, long minDelay, long maxDelay); static int getMaxOverhead(int numHops); Destination getNextDestination(); long getDelay(); void setSendTime(long sendTime); long getSendTime(); HashCash getHashCash(); byte[] getPayload(); CommunicationPacket getStoredPacket(I2PSession i2pSession); @Override byte[] toByteArray();  }