All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ByteArrayStreamextends ByteArrayOutputStream
OutputStream to InputStream adapter. Zero-copy where possible. Unsynchronized. This is NOT a Pipe. Do NOT reset after writing.
  • 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:
      reset in class ByteArrayOutputStream
      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. Use asInputStream() for guaranteed zero-copy.
      Overrides:
      toByteArray in class ByteArrayOutputStream
      Returns:
      the byte array containing the written data
    • asInputStream

      public ByteArrayInputStream 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 into
      offset - the offset in the target array
    • verifySignature

      public boolean verifySignature(Signature signature, SigningPublicKey verifyingKey)
      Verifies the signature of the written data.
      Parameters:
      signature - the signature to verify
      verifyingKey - 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 context
      signature - the signature to verify
      verifyingKey - the public key to verify with
      Returns:
      true if the signature is valid
    • sign

      public Signature sign(SigningPrivateKey signingKey)
      Signs the written data.
      Parameters:
      signingKey - the private key to sign with
      Returns:
      the signature, or null on error
    • sign

      public Signature sign(I2PAppContext ctx, SigningPrivateKey signingKey)
      Signs the written data.
      Parameters:
      ctx - the application context
      signingKey - the private key to sign with
      Returns:
      the signature, or null on error