Package org.aksw.iguana.commons.io
Class BigByteArrayOutputStream
java.lang.Object
java.io.OutputStream
org.aksw.iguana.commons.io.ReversibleOutputStream
org.aksw.iguana.commons.io.BigByteArrayOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
This class represents a ByteArrayOutputStream that can hold a large amount of byte data.
It is designed to overcome the limitations of the standard ByteArrayOutputStream, which
has a fixed internal byte array and can run into out of memory errors when trying to write
a large amount of data.
The BigByteArrayOutputStream works by using an ArrayList of ByteArrayOutputStreams to store
the byte data. When the current ByteArrayOutputStream fills up, a new one is created with the
maximum array size (Integer.MAX_VALUE - 8
) as its initial capacity and added to the list.
Writing data to the stream involves writing to the current active ByteArrayOutputStream. When
the stream is cleared, all the internal ByteArrayOutputStreams are cleared and a new one is
added to the list.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The maximum size limit for an array. -
Constructor Summary
ConstructorDescriptionInitializes a new instance of the BigByteArrayOutputStream class with default buffer size.BigByteArrayOutputStream
(int bufferSize) Initializes a new instance of the BigByteArrayOutputStream class with buffer size.BigByteArrayOutputStream
(long bufferSize) Initializes a new instance of the BigByteArrayOutputStream class with buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the state of the object by removing allByteArrayOutputStream
s from the baosList except for the first one.void
close()
List<org.apache.hadoop.hbase.io.ByteArrayOutputStream>
getBaos()
void
reset()
Resets the state of the object by setting the baosListIndex to zero and assigning the first ByteArrayOutputStream in the baosList to the currentBaos variable.long
size()
byte[][]
void
write
(byte b) void
write
(byte[][] byteArray) void
write
(byte[] b, int off, int len) void
write
(int i) void
write
(BigByteArrayOutputStream bbaos) Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Field Details
-
ARRAY_SIZE_LIMIT
public static final int ARRAY_SIZE_LIMITThe maximum size limit for an array. This is no limit to the amount of bytesBigByteArrayOutputStream
can consume.- See Also:
-
-
Constructor Details
-
BigByteArrayOutputStream
public BigByteArrayOutputStream()Initializes a new instance of the BigByteArrayOutputStream class with default buffer size. -
BigByteArrayOutputStream
public BigByteArrayOutputStream(int bufferSize) Initializes a new instance of the BigByteArrayOutputStream class with buffer size.- Parameters:
bufferSize
- initial guaranteed buffer size
-
BigByteArrayOutputStream
public BigByteArrayOutputStream(long bufferSize) Initializes a new instance of the BigByteArrayOutputStream class with buffer size.- Parameters:
bufferSize
- initial guaranteed buffer size
-
-
Method Details
-
getBaos
-
write
- Throws:
IOException
-
size
public long size()- Specified by:
size
in classReversibleOutputStream
-
toByteArray
public byte[][] toByteArray() -
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
reset
Resets the state of the object by setting the baosListIndex to zero and assigning the first ByteArrayOutputStream in the baosList to the currentBaos variable. NoByteArrayOutputStream
s are actually removed.- Throws:
IOException
-
clear
Clears the state of the object by removing allByteArrayOutputStream
s from the baosList except for the first one. The baosListIndex is set to 1 and the currentBaos variable is reassigned to the first ByteArrayOutputStream in the baosList.- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
toInputStream
- Specified by:
toInputStream
in classReversibleOutputStream
-