Class ByteArrayInOutStream

java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
io.mateu.core.infra.csv.ByteArrayInOutStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ByteArrayInOutStream extends ByteArrayOutputStream
This class extends the ByteArrayOutputStream by providing a method that returns a new ByteArrayInputStream which uses the internal byte array buffer. This buffer is not copied, so no additional memory is used. After creating the ByteArrayInputStream the instance of the ByteArrayInOutStream can not be used anymore.

The ByteArrayInputStream can be retrieved using getInputStream().

Author:
Nick Russler
  • Constructor Details

    • ByteArrayInOutStream

      public ByteArrayInOutStream()
      Creates a new ByteArrayInOutStream. The buffer capacity is initially 32 bytes, though its size increases if necessary.
    • ByteArrayInOutStream

      public ByteArrayInOutStream(int size)
      Creates a new ByteArrayInOutStream, with a buffer capacity of the specified size, in bytes.
      Parameters:
      size - the initial size.
      Throws:
      IllegalArgumentException - if size is negative.
  • Method Details

    • getInputStream

      public ByteArrayInputStream getInputStream()
      Creates a new ByteArrayInputStream that uses the internal byte array buffer of this ByteArrayInOutStream instance as its buffer array. The initial value of pos is set to zero and the initial value of count is the number of bytes that can be read from the byte array. The buffer array is not copied. This instance of ByteArrayInOutStream can not be used anymore after calling this method.
      Returns:
      the ByteArrayInputStream instance