java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
net.i2p.util.ByteArrayStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
OutputStream to InputStream adapter. Zero-copy where possible. Unsynchronized. This is NOT a Pipe. Do NOT reset after writing.
Field Summary
Fields inherited from class ByteArrayOutputStream
buf, countConstructor Summary
ConstructorsConstructorDescriptionCreates a new byte array output stream.ByteArrayStream(int size) Creates a new byte array output stream with the specified size.Method Summary
All MethodsModifier and TypeMethodDescriptionCreates an input stream from the written data.voidcopyTo(byte[] target, int offset) Copies all written data to the target array.voidreset()Resets this stream to the beginning.sign(SigningPrivateKey signingKey) Signs the written data.sign(I2PAppContext ctx, SigningPrivateKey signingKey) Signs the written data.byte[]Returns the byte array containing the written data.booleanverifySignature(Signature signature, SigningPublicKey verifyingKey) Verifies the signature of the written data.booleanverifySignature(I2PAppContext ctx, Signature signature, SigningPublicKey verifyingKey) Verifies the signature of the written data.Methods inherited from class ByteArrayOutputStream
close, size, toString, toString, toString, write, write, writeBytes, writeToMethods inherited from class OutputStream
flush, nullOutputStream, write
Constructor Details
ByteArrayStream
public ByteArrayStream()Creates a new byte array output stream.ByteArrayStream
public ByteArrayStream(int size) Creates a new byte array output stream with the specified size.- Parameters:
size- the initial size of the internal buffer
Method Details
reset
public void reset()Resets this stream to the beginning.- Overrides:
resetin classByteArrayOutputStream- Throws:
IllegalStateException- if previously written
toByteArray
public byte[] toByteArray()Returns the byte array containing the written data. Zero-copy only if the data fills the buffer. UseasInputStream()for guaranteed zero-copy.- Overrides:
toByteArrayin classByteArrayOutputStream- Returns:
- the byte array containing the written data
asInputStream
Creates an input stream from the written data. All data previously written. Zero-copy. Not a Pipe. Data written after this call will not appear.- Returns:
- an input stream containing the written data
copyTo
public void copyTo(byte[] target, int offset) Copies all written data to the target array.- Parameters:
target- the array to copy the written data intooffset- the offset in the target array
verifySignature
Verifies the signature of the written data.- Parameters:
signature- the signature to verifyverifyingKey- the public key to verify with- Returns:
- true if the signature is valid
verifySignature
public boolean verifySignature(I2PAppContext ctx, Signature signature, SigningPublicKey verifyingKey) Verifies the signature of the written data.- Parameters:
ctx- the application contextsignature- the signature to verifyverifyingKey- the public key to verify with- Returns:
- true if the signature is valid
sign
Signs the written data.- Parameters:
signingKey- the private key to sign with- Returns:
- the signature, or null on error
sign
Signs the written data.- Parameters:
ctx- the application contextsigningKey- the private key to sign with- Returns:
- the signature, or null on error