Package net.i2p.util
Class ByteArrayStream
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
net.i2p.util.ByteArrayStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class ByteArrayStream extends ByteArrayOutputStream
OutputStream to InputStream adapter.
Zero-copy where possible. Unsynchronized.
This is NOT a Pipe.
Do NOT reset after writing.
- Since:
- 0.9.48
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ByteArrayStream()ByteArrayStream(int size) -
Method Summary
Modifier and Type Method Description ByteArrayInputStreamasInputStream()All data previously written.voidcopyTo(byte[] target, int offset)Copy all data to the targetvoidreset()Signaturesign(SigningPrivateKey signingKey)Sign the written dataSignaturesign(I2PAppContext ctx, SigningPrivateKey signingKey)Sign the written databyte[]toByteArray()Zero-copy only if the data fills the buffer.booleanverifySignature(Signature signature, SigningPublicKey verifyingKey)Verify the written databooleanverifySignature(I2PAppContext ctx, Signature signature, SigningPublicKey verifyingKey)Verify the written data
-
Constructor Details
-
ByteArrayStream
public ByteArrayStream() -
ByteArrayStream
public ByteArrayStream(int size)- Parameters:
size- if accurate, toByteArray() will be zero-copy
-
-
Method Details
-
reset
public void reset()- Overrides:
resetin classByteArrayOutputStream- Throws:
IllegalStateException- if previously written
-
toByteArray
public byte[] toByteArray()Zero-copy only if the data fills the buffer. Use asInputStream() for guaranteed zero-copy.- Overrides:
toByteArrayin classByteArrayOutputStream
-
asInputStream
All data previously written. Zero-copy. Not a Pipe. Data written after this call will not appear. -
copyTo
public void copyTo(byte[] target, int offset)Copy all data to the target -
verifySignature
Verify the written data -
verifySignature
public boolean verifySignature(I2PAppContext ctx, Signature signature, SigningPublicKey verifyingKey)Verify the written data -
sign
Sign the written data- Returns:
- null on error
-
sign
Sign the written data- Returns:
- null on error
-