Class ZeroingByteArrayOutputStream

java.lang.Object
java.io.OutputStream
com.yubico.yubikit.core.util.ZeroingByteArrayOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public final class ZeroingByteArrayOutputStream extends OutputStream
A ByteArrayOutputStream replacement that zeros its internal buffer on close() and reset().
  • Constructor Details

    • ZeroingByteArrayOutputStream

      public ZeroingByteArrayOutputStream()
      Creates a new instance with the default initial capacity of 32 bytes.
    • ZeroingByteArrayOutputStream

      public ZeroingByteArrayOutputStream(int initialCapacity)
      Creates a new instance with the specified initial capacity.
  • Method Details

    • write

      public void write(int b)
      Specified by:
      write in class OutputStream
    • write

      public void write(byte[] b, int off, int len)
      Overrides:
      write in class OutputStream
    • toByteArray

      public byte[] toByteArray()
      Returns a copy of the data written so far.
    • size

      public int size()
      Returns the current number of bytes written.
    • reset

      public void reset()
      Zeros the internal buffer contents and resets the position to 0.
    • close

      public void close()
      Zeros the internal buffer. Idempotent.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
    • writeTo

      public void writeTo(OutputStream out) throws IOException
      Writes the contents to another stream.
      Throws:
      IOException