Class FragmentedOutputStream

java.lang.Object
com.swiftmq.net.protocol.util.FragmentedOutputStream

public class FragmentedOutputStream extends Object
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.

  • Constructor Details

    • FragmentedOutputStream

      public FragmentedOutputStream(int fragmentSize, boolean includeLength)
  • Method Details

    • getCurrentFragment

      public FragmentedOutputStream.Fragment 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

      public FragmentedOutputStream.Fragment getFragment(int index)