Package com.swiftmq.net.protocol.util
Class FragmentedOutputStream
java.lang.Object
com.swiftmq.net.protocol.util.FragmentedOutputStream
The FragmentedOutputStream class is designed for efficient network transmission
by breaking down data into manageable fragments. It provides an output stream that
collects written data into fixed-size byte arrays, referred to as fragments.
This approach is particularly useful for network protocols that require data to be
sent in discrete chunks and can help to align with network packet sizes to optimize transmission.
The class offers functionality to write data byte by byte or in byte arrays, manage the size of each fragment, and to optionally include the overall length of the data at the beginning of the stream. It leverages an internal pooling mechanism to minimize garbage collection overhead by reusing byte arrays where possible. This is particularly useful in high-throughput scenarios where stream reset and reuse are common.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
finish()
getFragment
(int index) int
void
reset()
void
write
(byte[] b, int off, int len) void
write
(int b)
-
Constructor Details
-
FragmentedOutputStream
public FragmentedOutputStream(int fragmentSize, boolean includeLength)
-
-
Method Details
-
getCurrentFragment
-
write
public void write(int b) -
write
public void write(byte[] b, int off, int len) -
finish
public void finish() -
reset
public void reset() -
getFragmentCount
public int getFragmentCount() -
getFragment
-