Package net.targetr.wtm3.io
Class ReusableBufferList
java.lang.Object
net.targetr.wtm3.io.ReusableBufferList
A list of reusable buffers.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new empty ReusableBufferList.ReusableBufferList(byte[] data) Constructs a new ReusableBufferList with a single byte array. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(byte[] data) Adds a byte array to the list.voidadd(byte[] data, int offset, int length) Adds a segment of a byte array to the list.voidadd(ReusableBuffer buffer) Adds a reusable buffer to the list.voidadd(ReusableBufferList buffers) Adds all buffers from another list to this list.voidclear()Clears all buffers from this list.split(byte splitByte) Splits this buffer list into two lists.byte[]Creates a single byte array containing all data from the buffers.intCalculates the total size in bytes of all buffers in the list.voidwriteTo(OutputStream out) Writes all buffers in this list to the given output stream.
-
Constructor Details
-
ReusableBufferList
public ReusableBufferList()Constructs a new empty ReusableBufferList. -
ReusableBufferList
public ReusableBufferList(byte[] data) Constructs a new ReusableBufferList with a single byte array.- Parameters:
data- the initial byte array
-
-
Method Details
-
add
public void add(byte[] data) Adds a byte array to the list.- Parameters:
data- the byte array to add
-
add
public void add(byte[] data, int offset, int length) Adds a segment of a byte array to the list.- Parameters:
data- the byte arrayoffset- the offset in the byte arraylength- the length to add
-
add
Adds a reusable buffer to the list.- Parameters:
buffer- the buffer to add
-
add
Adds all buffers from another list to this list.- Parameters:
buffers- the list of buffers to add
-
totalSizeInBytes
public int totalSizeInBytes()Calculates the total size in bytes of all buffers in the list.- Returns:
- the total size in bytes
-
writeTo
Writes all buffers in this list to the given output stream.- Parameters:
out- the output stream to write to- Throws:
IOException- if an I/O error occurs
-
toByteArray
public byte[] toByteArray()Creates a single byte array containing all data from the buffers.- Returns:
- a single byte array containing all the data
-
clear
public void clear()Clears all buffers from this list. -
split
Splits this buffer list into two lists. The first list will be up to split byte and the second list will be after split byte.- Parameters:
splitByte- the byte value to split on- Returns:
- an array containing two ReusableBufferLists: the first part and second part
-