use of i2p.bote.fileencryption.EncryptedOutputStream in project i2p.i2p-bote by i2p.
the class AddressBook method save.
public void save() throws IOException, PasswordException, GeneralSecurityException {
initializeIfNeeded();
OutputStream encryptedStream = new EncryptedOutputStream(new SecureFileOutputStream(addressFile), 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 <" + addressFile.getAbsolutePath() + ">.", e);
throw e;
} finally {
encryptedStream.close();
}
}
use of i2p.bote.fileencryption.EncryptedOutputStream in project i2p.i2p-bote by i2p.
the class EmailFolder method saveMetadata.
private void saveMetadata(EmailMetadata metadata, File file) throws PasswordException, FileNotFoundException, IOException, GeneralSecurityException {
log.info("Mail folder <" + storageDir + ">: storing metadata file: <" + file.getAbsolutePath() + ">");
OutputStream emailOutputStream = new BufferedOutputStream(new EncryptedOutputStream(new SecureFileOutputStream(file), passwordHolder));
try {
metadata.writeTo(emailOutputStream);
} catch (IOException e) {
log.error("Can't write metadata to file <" + file.getAbsolutePath() + ">", e);
throw e;
} finally {
if (emailOutputStream != null)
emailOutputStream.close();
}
for (FolderListener listener : folderListeners) listener.elementUpdated();
}
use of i2p.bote.fileencryption.EncryptedOutputStream 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 i2p.bote.fileencryption.EncryptedOutputStream in project i2p.i2p-bote by i2p.
the class MigrateTo027 method encrypt.
private void encrypt(File oldFile, File newFile) throws IOException, PasswordException, GeneralSecurityException {
InputStream inputStream = null;
byte[] contents = null;
try {
inputStream = new FileInputStream(oldFile);
contents = Util.readBytes(inputStream);
} finally {
if (inputStream != null)
inputStream.close();
}
EncryptedOutputStream encryptedStream = null;
try {
OutputStream fileOutputStream = new FileOutputStream(newFile);
encryptedStream = new EncryptedOutputStream(fileOutputStream, passwordCache);
if (contents != null)
encryptedStream.write(contents);
} finally {
if (encryptedStream != null)
encryptedStream.close();
}
}
use of i2p.bote.fileencryption.EncryptedOutputStream in project i2p.i2p-bote by i2p.
the class MigrateTo026 method encrypt.
private void encrypt(File oldFile, File newFile) throws IOException, PasswordException, GeneralSecurityException {
InputStream inputStream = null;
byte[] contents = null;
try {
inputStream = new FileInputStream(oldFile);
contents = Util.readBytes(inputStream);
} finally {
if (inputStream != null)
inputStream.close();
}
EncryptedOutputStream encryptedStream = null;
try {
OutputStream fileOutputStream = new FileOutputStream(newFile);
encryptedStream = new EncryptedOutputStream(fileOutputStream, passwordCache);
if (contents != null)
encryptedStream.write(contents);
} finally {
if (encryptedStream != null)
encryptedStream.close();
}
}
Aggregations