Class FastByteArrayOutputStream

    • Constructor Detail

      • FastByteArrayOutputStream

        public FastByteArrayOutputStream()
        Creates a new byte array output stream. The buffer capacity is initially 32 bytes, though its size increases if necessary.
      • FastByteArrayOutputStream

        public FastByteArrayOutputStream​(int size)
        Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
        Parameters:
        size - the initial size.
        Throws:
        IllegalArgumentException - if size is negative.
    • Method Detail

      • write

        public void write​(int b)
        Writes the specified byte to this byte array output stream.
        Specified by:
        write in class OutputStream
        Parameters:
        b - the byte to be written.
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
        Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
        Overrides:
        write in class OutputStream
        Parameters:
        b - the data.
        off - the start offset in the data.
        len - the number of bytes to write.
      • toByteArray

        public byte[] toByteArray()
        returns inner array
        Returns:
        the current contents of this output stream, as a byte array.
      • size

        public int size()
        Returns the current size of the buffer.
        Returns:
        the value of the count field, which is the number of valid bytes in this output stream.
      • close

        public void close()
                   throws IOException
        Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Overrides:
        close in class OutputStream
        Throws:
        IOException
      • copyFrom

        public void copyFrom​(FastByteArrayInputStream source,
                             int offset,
                             int count)
        Copies data from input stream
        Parameters:
        source - source stream
        offset - offset in the source
        count - number of bytes to copy
      • convertToInputStream

        public FastByteArrayInputStream convertToInputStream()
        Creates InputStream using the same data that is written into this stream with no copying in memory
        Returns:
        a input stream contained all bytes recorded in a current stream
      • getBuffer

        public byte[] getBuffer()
      • reset

        public void reset()