use of net.i2p.util.SecureFileOutputStream in project i2p.i2p-bote by i2p.
the class EmailFolder method add.
/**
* Stores an email in the folder. If an email with the same
* message ID exists already, nothing happens.
* @param email
* @throws IOException
* @throws MessagingException
* @throws PasswordException
* @throws GeneralSecurityException
*/
public void add(Email email) throws IOException, MessagingException, PasswordException, GeneralSecurityException {
// check if an email exists already with that message id
if (getEmailFile(email.getMessageID()).exists()) {
log.debug("Not storing email because there is an existing one with the same message ID: <" + email.getMessageID() + ">");
return;
}
// write out the email file
File emailFile = getEmailFile(email);
log.info("Mail folder <" + storageDir + ">: storing email file: <" + emailFile.getAbsolutePath() + ">");
OutputStream emailOutputStream = new BufferedOutputStream(new EncryptedOutputStream(new SecureFileOutputStream(emailFile), passwordHolder));
try {
email.writeTo(emailOutputStream);
} finally {
emailOutputStream.close();
}
saveMetadata(email);
for (FolderListener listener : folderListeners) listener.elementAdded(email.getMessageID());
}
use of net.i2p.util.SecureFileOutputStream in project i2p.i2p-bote by i2p.
the class MessageIdCache method write.
private void write(File cacheFile) {
log.debug("Writing message ID cache file: <" + cacheFile.getAbsolutePath() + ">");
String newLine = System.getProperty("line.separator");
Writer writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(cacheFile.getAbsolutePath())));
for (UniqueId id : idList) writer.write(id.toBase64() + newLine);
} catch (IOException e) {
log.error("Can't write message ID cache file.", e);
} finally {
if (writer != null)
try {
writer.close();
} catch (IOException e) {
log.error("Error closing Writer.", e);
}
}
}
use of net.i2p.util.SecureFileOutputStream in project i2p.i2p-bote by i2p.
the class PacketFolder method add.
/**
* 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();
}
}
}
}
use of net.i2p.util.SecureFileOutputStream in project i2p.i2p-bote by i2p.
the class Identities method save.
/**
* Saves all identities to file.
*/
public void save() throws IOException, GeneralSecurityException, PasswordException {
initializeIfNeeded();
OutputStream encryptedStream = new EncryptedOutputStream(new SecureFileOutputStream(identitiesFile), passwordHolder);
try {
Properties properties = saveToProperties();
properties.store(new OutputStreamWriter(encryptedStream, "UTF-8"), null);
} catch (IOException e) {
log.error("Can't save email identities to file <" + identitiesFile.getAbsolutePath() + ">.", e);
throw e;
} finally {
encryptedStream.close();
}
}
use of net.i2p.util.SecureFileOutputStream in project i2p.i2p-bote by i2p.
the class RelayPeerManager method writePeers.
private void writePeers(File file) {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(file.getAbsolutePath())));
writer.write("# Each line is in the format: <dest> [resp1] [resp2] ...");
writer.newLine();
writer.write("# dest = the I2P destination");
writer.newLine();
writer.write("# resp* = true or false, depending on whether the peer responded");
writer.newLine();
writer.write("# The fields are separated by a tab character.");
writer.newLine();
writer.write("# Lines starting with a # are ignored.");
writer.newLine();
writer.write("# Do not edit this file while I2P-Bote is running as it will be overwritten.");
writer.newLine();
for (RelayPeer peer : peers) {
writer.write(peer.toBase64());
for (boolean responded : peer.getAllSamples()) writer.write("\t" + responded);
writer.newLine();
}
} catch (IOException e) {
log.error("Can't write peers to file <" + file.getAbsolutePath() + ">", e);
} finally {
if (writer != null)
try {
writer.close();
} catch (IOException e) {
log.error("Can't close BufferedWriter for file <" + file.getAbsolutePath() + ">", e);
}
}
}
Aggregations