@Test public void testToByteArrayAndBack() throws GeneralSecurityException { IndexPacket newPacket1 = new IndexPacket(indexPacket1.toByteArray()); assertTrue("The two packets differ!", equal(indexPacket1, newPacket1)); IndexPacket newPacket2 = new IndexPacket(indexPacket2.toByteArray()); assertTrue("The two packets differ!", equal(indexPacket2, newPacket2)); }
@Override public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); try { writeHeader(dataStream); destinationHash.writeBytes(dataStream); dataStream.writeInt(entries.size()); for (IndexPacketEntry entry: entries) { dataStream.write(entry.emailPacketKey.toByteArray()); dataStream.write(entry.delVerificationHash.toByteArray()); dataStream.writeInt((int)(entry.storeTime/1000L)); } } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream/DataOutputStream.", e); } catch (DataFormatException e) { log.error("Can't write destination hash to output stream: " + destinationHash, e); } return byteStream.toByteArray(); }
IndexPacket extends DhtStorablePacket implements Iterable<IndexPacketEntry>, Splittable { @Override public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); try { writeHeader(dataStream); destinationHash.writeBytes(dataStream); dataStream.writeInt(entries.size()); for (IndexPacketEntry entry: entries) { dataStream.write(entry.emailPacketKey.toByteArray()); dataStream.write(entry.delVerificationHash.toByteArray()); dataStream.writeInt((int)(entry.storeTime/1000L)); } } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream/DataOutputStream.", e); } catch (DataFormatException e) { log.error("Can't write destination hash to output stream: " + destinationHash, e); } return byteStream.toByteArray(); } }
IndexPacket extends DhtStorablePacket implements Iterable<IndexPacketEntry>, Splittable { @Override public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); try { writeHeader(dataStream); destinationHash.writeBytes(dataStream); dataStream.writeInt(entries.size()); for (IndexPacketEntry entry: entries) { dataStream.write(entry.emailPacketKey.toByteArray()); dataStream.write(entry.delVerificationHash.toByteArray()); dataStream.writeInt((int)(entry.storeTime/1000L)); } } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream/DataOutputStream.", e); } catch (DataFormatException e) { log.error("Can't write destination hash to output stream: " + destinationHash, e); } return byteStream.toByteArray(); } IndexPacket(EmailDestination emailDestination);  IndexPacket(Hash destinationHash);  IndexPacket(Collection<IndexPacket> indexPackets);  IndexPacket(IndexPacket... indexPackets);  IndexPacket(byte[] data); }
IndexPacket extends DhtStorablePacket implements Iterable<IndexPacketEntry>, Splittable { @Override public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); try { writeHeader(dataStream); destinationHash.writeBytes(dataStream); dataStream.writeInt(entries.size()); for (IndexPacketEntry entry: entries) { dataStream.write(entry.emailPacketKey.toByteArray()); dataStream.write(entry.delVerificationHash.toByteArray()); dataStream.writeInt((int)(entry.storeTime/1000L)); } } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream/DataOutputStream.", e); } catch (DataFormatException e) { log.error("Can't write destination hash to output stream: " + destinationHash, e); } return byteStream.toByteArray(); } IndexPacket(EmailDestination emailDestination);  IndexPacket(Hash destinationHash);  IndexPacket(Collection<IndexPacket> indexPackets);  IndexPacket(IndexPacket... indexPackets);  IndexPacket(byte[] data); @Override byte[] toByteArray(); void put(EncryptedEmailPacket emailPacket); void put(Collection<EncryptedEmailPacket> emailPackets); void put(IndexPacketEntry entry); Hash getDeleteVerificationHash(Hash emailPacketKey); void remove(Hash emailPacketKey); boolean contains(Hash emailPacketKey); @Override Hash getDhtKey(); int getNumEntries(); @Override Iterator<IndexPacketEntry> iterator(); @Override Collection<? extends DataPacket> split(); }
IndexPacket extends DhtStorablePacket implements Iterable<IndexPacketEntry>, Splittable { @Override public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); try { writeHeader(dataStream); destinationHash.writeBytes(dataStream); dataStream.writeInt(entries.size()); for (IndexPacketEntry entry: entries) { dataStream.write(entry.emailPacketKey.toByteArray()); dataStream.write(entry.delVerificationHash.toByteArray()); dataStream.writeInt((int)(entry.storeTime/1000L)); } } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream/DataOutputStream.", e); } catch (DataFormatException e) { log.error("Can't write destination hash to output stream: " + destinationHash, e); } return byteStream.toByteArray(); } IndexPacket(EmailDestination emailDestination);  IndexPacket(Hash destinationHash);  IndexPacket(Collection<IndexPacket> indexPackets);  IndexPacket(IndexPacket... indexPackets);  IndexPacket(byte[] data); @Override byte[] toByteArray(); void put(EncryptedEmailPacket emailPacket); void put(Collection<EncryptedEmailPacket> emailPackets); void put(IndexPacketEntry entry); Hash getDeleteVerificationHash(Hash emailPacketKey); void remove(Hash emailPacketKey); boolean contains(Hash emailPacketKey); @Override Hash getDhtKey(); int getNumEntries(); @Override Iterator<IndexPacketEntry> iterator(); @Override Collection<? extends DataPacket> split();  }