public class SecureByteArrayOutputStream
extends java.io.OutputStream
The buffer automatically grows as data is written to it, and any temporary data is wiped following use.
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
Buffer where data is stored.
|
protected int |
count
Number of valid bytes in the buffer.
|
| Constructor and Description |
|---|
SecureByteArrayOutputStream()
Creates a new
SecureByteArrayOutputStream. |
SecureByteArrayOutputStream(int size)
Creates a new
SecureByteArrayOutputStream, with a buffer
capacity of size bytes. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closing a
SecureByteArrayOutputStream has no effect. |
void |
reset()
Wipes the contents of the buffer, so that all accumulated output is
destroyed.
|
int |
size()
Returns the number of bytes held in the output stream.
|
byte[] |
toByteArray()
Returns a
byte[] that holds the contents of this output stream. |
SecureByteArray |
toSecureByteArray()
Returns a
SecureByteArray that holds the contents of this
output stream. |
SecureByteArray |
toSecureByteArray(int sensitivity)
Returns a
SecureByteArray that holds the contents of this
output stream with the specified sensitivity. |
void |
write(byte[] ba)
Writes
ba.length bytes from the specified byte array to this
SecureByteArrayOutputStream. |
void |
write(byte[] ba,
int off,
int len)
Writes
len bytes from the specified byte array starting at
offset off to this SecureByteArrayOutputStream. |
void |
write(int b)
Writes the specified byte to this
SecureByteArrayOutputStream. |
protected byte[] buf
protected int count
public SecureByteArrayOutputStream()
SecureByteArrayOutputStream.
The buffer capacity is initially 32 bytes, but its size increases if necessary.
public SecureByteArrayOutputStream(int size)
SecureByteArrayOutputStream, with a buffer
capacity of size bytes.size - initial buffer sizepublic void close()
SecureByteArrayOutputStream has no effect.
The methods in this class can be called after the stream has been closed
without generating an IOException.
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.OutputStreampublic void reset()
The SecureByteArrayOutputStream can be used again, reusing the
already allocated buffer space.
public int size()
public byte[] toByteArray()
byte[] that holds the contents of this output stream.
Creates a newly allocated byte array. Its size is the current size of this output stream and the valid contents of the buffer have been copied into it.
SecureByteArrayOutputStream are
not wiped following this call. If you want to destroy the
contents, use the reset() method to wipe the contents
of the SecureByteArrayOutputStream object.byte[] is cleared
after use.byte[] that holds the contents of this output streampublic SecureByteArray toSecureByteArray()
SecureByteArray that holds the contents of this
output stream.
Creates a newly allocated SecureByteArray. Its size is the
current size of this output stream and the valid contents of the buffer
have been copied into it.
The sensitivity is set to the default value BASE.
SecureByteArrayOutputStream are
not wiped following this call. If you want to destroy the
contents, use the reset() method to wipe the contents
of the SecureByteArrayOutputStream object.SecureByteArray that holds the contents of this
output streampublic SecureByteArray toSecureByteArray(int sensitivity)
SecureByteArray that holds the contents of this
output stream with the specified sensitivity.
Creates a newly allocated SecureByteArray. Its size is the
current size of this output stream and the valid contents of the buffer
have been copied into it.
SecureByteArrayOutputStream are
not wiped following this call. If you want to destroy the
contents, use the reset() method to wipe the contents
of the SecureByteArrayOutputStream object.sensitivity - sensitivity of the dataSecureByteArray that holds the contents of this
output streampublic void write(byte[] ba)
ba.length bytes from the specified byte array to this
SecureByteArrayOutputStream.
If the internal buffer needs to be expanded, a new one is created and the old one is wiped to ensure that only one copy of the data exists in memory.
ba is not wiped by this method,
but all internal temporary data is wiped prior to returning. If
want to destroy the contents of ba, use the
SecureUtils.wipe(byte []) method.write in class java.io.OutputStreamba - the byte array of data to be writtenpublic void write(byte[] ba,
int off,
int len)
len bytes from the specified byte array starting at
offset off to this SecureByteArrayOutputStream.
If the buffer needs to be expanded, a new one is created and the old one is wiped to ensure that only one copy of the data exists in memory.
ba is not wiped by this method,
but all internal temporary data is wiped prior to returning. If
want to destroy the contents of ba, use the
SecureUtils.wipe(byte []) method.write in class java.io.OutputStreamba - the byte array data to be writtenoff - the start offset in the datalen - the number of bytes to writepublic void write(int b)
SecureByteArrayOutputStream.
If the buffer needs to be expanded, a new one is created and the old one is wiped to ensure that only one copy of the data exists in memory.
write in class java.io.OutputStreamb - the byte to be written