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
-
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
-
-
Constructor Summary
Constructors Constructor Description ByteArrayStream()
ByteArrayStream(int size)
-
Method Summary
All Methods Instance Methods Concrete Methods 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-
Methods 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
-
-
-
-
Method Detail
-
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
public ByteArrayInputStream 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
public boolean verifySignature(Signature signature, SigningPublicKey verifyingKey)
Verify the written data
-
verifySignature
public boolean verifySignature(I2PAppContext ctx, Signature signature, SigningPublicKey verifyingKey)
Verify the written data
-
sign
public Signature sign(SigningPrivateKey signingKey)
Sign the written data- Returns:
- null on error
-
sign
public Signature sign(I2PAppContext ctx, SigningPrivateKey signingKey)
Sign the written data- Returns:
- null on error
-
-