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
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum size limit for an array. -
Constructor Summary
ConstructorsConstructorDescriptionInitializes 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 TypeMethodDescriptionvoidclear()Clears the state of the object by removing allByteArrayOutputStreams from the baosList except for the first one.voidclose()List<org.apache.hadoop.hbase.io.ByteArrayOutputStream>getBaos()voidreset()Resets the state of the object by setting the baosListIndex to zero and assigning the first ByteArrayOutputStream in the baosList to the currentBaos variable.longsize()byte[][]voidwrite(byte b) voidwrite(byte[][] byteArray) voidwrite(byte[] b, int off, int len) voidwrite(int i) voidwrite(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 bytesBigByteArrayOutputStreamcan 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:
sizein classReversibleOutputStream
-
toByteArray
public byte[][] toByteArray() -
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Specified by:
writein 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. NoByteArrayOutputStreams are actually removed.- Throws:
IOException
-
clear
Clears the state of the object by removing allByteArrayOutputStreams 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
toInputStream
- Specified by:
toInputStreamin classReversibleOutputStream
-