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 ByteArrayInputStream
asInputStream()
All data previously written.void
copyTo(byte[] target, int offset)
Copy all data to the targetvoid
reset()
Signature
sign(SigningPrivateKey signingKey)
Sign the written dataSignature
sign(I2PAppContext ctx, SigningPrivateKey signingKey)
Sign the written databyte[]
toByteArray()
Zero-copy only if the data fills the buffer.boolean
verifySignature(Signature signature, SigningPublicKey verifyingKey)
Verify the written databoolean
verifySignature(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:
reset
in 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:
toByteArray
in 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
-