@Test public void testAddRemove() { folder.add(relayRequest); Iterator<RelayRequest> iterator = folder.iterator(); assertTrue("Folder is empty after a packet was added to it!", iterator.hasNext()); RelayRequest storedPacket = iterator.next(); byte[] arrayA = relayRequest.toByteArray(); byte[] arrayB = storedPacket.toByteArray(); assertArrayEquals("The two arrays differ!", arrayA, arrayB); assertFalse("Folder has more than one element!", iterator.hasNext()); iterator.remove(); assertFalse("Packet was not deleted!", folder.iterator().hasNext()); }
public void add(RelayRequest packet) { byte[] bytes = packet.toByteArray(); Hash packetHash = SHA256Generator.getInstance().calculateHash(bytes); String base64Hash = packetHash.toBase64(); if (!fileExistsForHash(base64Hash)) { long sendTime = System.currentTimeMillis() + packet.getDelay(); String filename = sendTime + "_" + base64Hash + PACKET_FILE_EXTENSION; add(packet, filename); return; } }
RelayPacketFolder extends PacketFolder<RelayRequest> { public void add(RelayRequest packet) { byte[] bytes = packet.toByteArray(); Hash packetHash = SHA256Generator.getInstance().calculateHash(bytes); String base64Hash = packetHash.toBase64(); if (!fileExistsForHash(base64Hash)) { long sendTime = System.currentTimeMillis() + packet.getDelay(); String filename = sendTime + "_" + base64Hash + PACKET_FILE_EXTENSION; add(packet, filename); return; } } }
RelayPacketFolder extends PacketFolder<RelayRequest> { public void add(RelayRequest packet) { byte[] bytes = packet.toByteArray(); Hash packetHash = SHA256Generator.getInstance().calculateHash(bytes); String base64Hash = packetHash.toBase64(); if (!fileExistsForHash(base64Hash)) { long sendTime = System.currentTimeMillis() + packet.getDelay(); String filename = sendTime + "_" + base64Hash + PACKET_FILE_EXTENSION; add(packet, filename); return; } } RelayPacketFolder(File storageDir); }
RelayPacketFolder extends PacketFolder<RelayRequest> { public void add(RelayRequest packet) { byte[] bytes = packet.toByteArray(); Hash packetHash = SHA256Generator.getInstance().calculateHash(bytes); String base64Hash = packetHash.toBase64(); if (!fileExistsForHash(base64Hash)) { long sendTime = System.currentTimeMillis() + packet.getDelay(); String filename = sendTime + "_" + base64Hash + PACKET_FILE_EXTENSION; add(packet, filename); return; } } RelayPacketFolder(File storageDir); void add(RelayRequest packet); }
RelayPacketFolder extends PacketFolder<RelayRequest> { public void add(RelayRequest packet) { byte[] bytes = packet.toByteArray(); Hash packetHash = SHA256Generator.getInstance().calculateHash(bytes); String base64Hash = packetHash.toBase64(); if (!fileExistsForHash(base64Hash)) { long sendTime = System.currentTimeMillis() + packet.getDelay(); String filename = sendTime + "_" + base64Hash + PACKET_FILE_EXTENSION; add(packet, filename); return; } } RelayPacketFolder(File storageDir); void add(RelayRequest packet);  }