Class Pack7LStreamWriter

java.lang.Object
zeroecho.sdk.util.Pack7LStreamWriter

public class Pack7LStreamWriter extends Object
A streaming writer that reads a variable-length 7-bit encoded length prefix from the input data and writes the subsequent payload to a target OutputStream.

The write(byte[]) method can be called multiple times, even with partial data. It will return how many bytes from the input array were consumed.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new Pack7LStreamWriter.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks whether the payload has been fully written.
    int
    write(byte[] data)
    Writes the given data to the internal buffer or to the output stream once the length prefix has been fully decoded.
    int
    write(byte[] data, int offset, int length)
    Processes a chunk of input data starting at the specified offset and up to the specified length.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Pack7LStreamWriter

      public Pack7LStreamWriter(OutputStream out)
      Constructs a new Pack7LStreamWriter.
      Parameters:
      out - the OutputStream where the payload will be written after decoding the length
  • Method Details

    • write

      public int write(byte[] data) throws IOException
      Writes the given data to the internal buffer or to the output stream once the length prefix has been fully decoded. Returns how many bytes from data were consumed.
      Parameters:
      data - the input byte array, possibly containing a length prefix and/or payload
      Returns:
      the number of bytes consumed from data
      Throws:
      IOException - if an I/O error occurs while writing to the output stream
    • write

      public int write(byte[] data, int offset, int length) throws IOException
      Processes a chunk of input data starting at the specified offset and up to the specified length.

      On the first call(s), this method reads a variable-length 7-bit encoded prefix from the input data, which specifies how many total bytes are expected to follow. Once the prefix is fully read, the method writes up to the remaining number of payload bytes to the underlying OutputStream.

      This method is designed to be called repeatedly with partial or complete input buffers. It maintains internal state and will continue consuming input until the expected number of payload bytes are written.

      Parameters:
      data - the input byte array containing part of the length prefix and/or payload; must not be null
      offset - the starting position in the array to read from
      length - the number of bytes to read from the array
      Returns:
      the number of bytes consumed from the input buffer
      Throws:
      IOException - if an I/O error occurs during writing or if the length prefix is malformed
      IndexOutOfBoundsException - if offset or length are invalid for the given array
    • isComplete

      public boolean isComplete()
      Checks whether the payload has been fully written.
      Returns:
      true if all expected payload bytes have been written and the length has been decoded; false otherwise.