Class Pack7LStreamWriter
java.lang.Object
zeroecho.sdk.util.Pack7LStreamWriter
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 -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether the payload has been fully written.intwrite(byte[] data) Writes the given data to the internal buffer or to the output stream once the length prefix has been fully decoded.intwrite(byte[] data, int offset, int length) Processes a chunk of input data starting at the specified offset and up to the specified length.
-
Constructor Details
-
Pack7LStreamWriter
Constructs a newPack7LStreamWriter.- Parameters:
out- theOutputStreamwhere the payload will be written after decoding the length
-
-
Method Details
-
write
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 fromdatawere 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
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 benulloffset- the starting position in the array to read fromlength- 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 malformedIndexOutOfBoundsException- ifoffsetorlengthare invalid for the given array
-
isComplete
public boolean isComplete()Checks whether the payload has been fully written.- Returns:
trueif all expected payload bytes have been written and the length has been decoded;falseotherwise.
-