/** * Saves a packet to a file in the folder. If the file already exists, it is overwritten. * @param packetToStore * @param filename The filename to store the packet under, relative to this folder's storage directory. */ protected void add(I2PBotePacket packetToStore, String filename) { FileOutputStream outputStream = null; File file = new File(storageDir, filename); try { outputStream = new SecureFileOutputStream(file); packetToStore.writeTo(outputStream); } catch (Exception e) { log.error("Can't save packet to file: <" + filename + ">", e); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { log.error("Can't close file: <" + filename + ">", e); } if (file.length() == 0) { log.error("Nothing was written, deleting empty file: <" + file.getAbsolutePath() + ">"); file.delete(); } } } }