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
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
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAll data previously written.void
copyTo
(byte[] target, int offset) Copy all data to the targetvoid
reset()
sign
(SigningPrivateKey signingKey) Sign the written datasign
(I2PAppContext ctx, SigningPrivateKey signingKey) Sign the written databyte[]
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 dataMethods inherited from class java.io.ByteArrayOutputStream
close, size, toString, toString, toString, toString, write, write, writeBytes, writeTo
Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
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
-