Package io.mateu.core.infra.csv
Class ByteArrayInOutStream
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
io.mateu.core.infra.csv.ByteArrayInOutStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
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
-
Field Summary
Fields inherited from class java.io.ByteArrayOutputStream
buf, count -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ByteArrayInOutStream.ByteArrayInOutStream(int size) Creates a new ByteArrayInOutStream, with a buffer capacity of the specified size, in bytes. -
Method Summary
Modifier and TypeMethodDescriptionCreates a new ByteArrayInputStream that uses the internal byte array buffer of this ByteArrayInOutStream instance as its buffer array.Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, toString, write, write, writeBytes, writeToMethods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
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
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
-