@Test public void toByteArrayAndBack() { byte[] arrayA = packet.toByteArray(); byte[] arrayB = new UnencryptedEmailPacket(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); messageId.writeTo(dataStream); delAuthorization.writeTo(dataStream); dataStream.writeShort(fragmentIndex); dataStream.writeShort(numFragments); dataStream.writeShort(content.length); dataStream.write(content); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); }
UnencryptedEmailPacket extends DataPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteArrayStream); try { writeHeader(dataStream); messageId.writeTo(dataStream); delAuthorization.writeTo(dataStream); dataStream.writeShort(fragmentIndex); dataStream.writeShort(numFragments); dataStream.writeShort(content.length); dataStream.write(content); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } }
UnencryptedEmailPacket extends DataPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteArrayStream); try { writeHeader(dataStream); messageId.writeTo(dataStream); delAuthorization.writeTo(dataStream); dataStream.writeShort(fragmentIndex); dataStream.writeShort(numFragments); dataStream.writeShort(content.length); dataStream.write(content); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } UnencryptedEmailPacket(InputStream inputStream);  UnencryptedEmailPacket(InputStream inputStream, UniqueId messageId, int fragmentIndex, int maxPacketSize);  UnencryptedEmailPacket(byte[] data); }
UnencryptedEmailPacket extends DataPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteArrayStream); try { writeHeader(dataStream); messageId.writeTo(dataStream); delAuthorization.writeTo(dataStream); dataStream.writeShort(fragmentIndex); dataStream.writeShort(numFragments); dataStream.writeShort(content.length); dataStream.write(content); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } UnencryptedEmailPacket(InputStream inputStream);  UnencryptedEmailPacket(InputStream inputStream, UniqueId messageId, int fragmentIndex, int maxPacketSize);  UnencryptedEmailPacket(byte[] data); UniqueId getMessageId(); UniqueId getDeleteAuthorization(); int getFragmentIndex(); void setNumFragments(int numFragments); int getNumFragments(); byte[] getContent(); @Override byte[] toByteArray(); @Override String toString(); }
UnencryptedEmailPacket extends DataPacket { @Override public byte[] toByteArray() { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteArrayStream); try { writeHeader(dataStream); messageId.writeTo(dataStream); delAuthorization.writeTo(dataStream); dataStream.writeShort(fragmentIndex); dataStream.writeShort(numFragments); dataStream.writeShort(content.length); dataStream.write(content); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteArrayStream.toByteArray(); } UnencryptedEmailPacket(InputStream inputStream);  UnencryptedEmailPacket(InputStream inputStream, UniqueId messageId, int fragmentIndex, int maxPacketSize);  UnencryptedEmailPacket(byte[] data); UniqueId getMessageId(); UniqueId getDeleteAuthorization(); int getFragmentIndex(); void setNumFragments(int numFragments); int getNumFragments(); byte[] getContent(); @Override byte[] toByteArray(); @Override String toString();  }