Search in sources :

Example 1 with CrypterException

use of ddf.security.encryption.crypter.Crypter.CrypterException in project ddf by codice.

the class FileSystemStorageProvider method decryptStream.

private ByteSource decryptStream(InputStream contentInputStream) throws StorageException {
    ByteSource output = null;
    try (InputStream decryptedInputStream = crypter.decrypt(contentInputStream);
        FileBackedOutputStream decryptedOutputStream = new FileBackedOutputStream(128)) {
        // do not use try with resources in order to have these InputStreams in the finally block
        IOUtils.copy(decryptedInputStream, decryptedOutputStream);
        output = decryptedOutputStream.asByteSource();
    } catch (CrypterException | IOException e) {
        LOGGER.debug("Error decrypting InputStream {}. Failing StorageProvider read.", contentInputStream, e);
        throw new StorageException(String.format("Cannot decrypt InputStream %s.", contentInputStream), e);
    }
    return output;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteSource(com.google.common.io.ByteSource) FileBackedOutputStream(com.google.common.io.FileBackedOutputStream) IOException(java.io.IOException) CrypterException(ddf.security.encryption.crypter.Crypter.CrypterException) StorageException(ddf.catalog.content.StorageException)

Aggregations

ByteSource (com.google.common.io.ByteSource)1 FileBackedOutputStream (com.google.common.io.FileBackedOutputStream)1 StorageException (ddf.catalog.content.StorageException)1 CrypterException (ddf.security.encryption.crypter.Crypter.CrypterException)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1