K
- The type of MasterKey
s used to manipulate the data.public class CryptoOutputStream<K extends MasterKey<K>> extends OutputStream
The CryptoOutputStream wraps a provided OutputStream object and performs cryptographic transformation of the bytes written to it. The transformed bytes are then written to the wrapped OutputStream. It uses the cryptography handler provided during construction to invoke methods that perform the cryptographic transformations.
In short, writing to the CryptoOutputStream results in those bytes being cryptographically transformed and written to the wrapped OutputStream.
For example, if the crypto handler provides methods for decryption, the CryptoOutputStream will decrypt the provided ciphertext bytes and write the plaintext bytes to the wrapped OutputStream.
This class adheres strictly to the semantics, especially the failure semantics, of its ancestor class java.io.OutputStream. This class overrides all the methods specified in its ancestor class.
To instantiate an instance of this class, please see AwsCrypto
.
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this output stream and releases any system resources associated with this stream.
|
CryptoResult<CryptoOutputStream<K>,K> |
getCryptoResult()
Returns the result of the cryptographic operations including associate metadata.
|
void |
setMaxInputLength(long size)
Sets an upper bound on the size of the input data.
|
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
flush
public void write(byte[] b) throws IllegalArgumentException, IOException, BadCiphertextException
write
in class OutputStream
BadCiphertextException
- This is thrown only during decryption if b contains invalid or
corrupt ciphertext.IllegalArgumentException
IOException
public void write(byte[] b, int off, int len) throws IllegalArgumentException, IOException, BadCiphertextException
write
in class OutputStream
BadCiphertextException
- This is thrown only during decryption if b contains invalid or
corrupt ciphertext.IllegalArgumentException
IOException
public void write(int b) throws IOException, BadCiphertextException
write
in class OutputStream
BadCiphertextException
- This is thrown only during decryption if b contains invalid or
corrupt ciphertext.IOException
public void close() throws IOException, BadCiphertextException
This method writes any final bytes to the underlying stream that complete the cyptographic transformation of the written bytes. It also calls close on the wrapped OutputStream.
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
- if an I/O error occurs.BadCiphertextException
- This is thrown only during decryption if b contains invalid or
corrupt ciphertext.public void setMaxInputLength(long size)
Among other things, this size is used to enforce limits configured on the CachingCryptoMaterialsManager
.
If the size set here is exceeded, an exception will be thrown, and the encyption or decryption will fail.
If this method is called multiple times, the smallest bound will be used.
size
- Maximum input size.public CryptoResult<CryptoOutputStream<K>,K> getCryptoResult()
Copyright © 2023. All rights reserved.