Package io.bytestreams.codec.core
Class StreamHexStringCodec
java.lang.Object
io.bytestreams.codec.core.StreamHexStringCodec
A codec for variable-length hexadecimal strings that reads all remaining bytes from the stream.
Unlike FixedHexStringCodec, which reads a fixed number of hex digits, this codec reads
all bytes until EOF. This makes it suitable for use as a value codec inside VariableByteLengthCodec, where the stream is bounded by the length prefix.
Encode pads odd-length values to even by left-padding with '0'. Decode always returns an even-length hex string. Encode accepts both uppercase and lowercase hex digits. Decode always returns uppercase.
Codec<String> codec = Codecs.hex();
-
Method Summary
Modifier and TypeMethodDescriptiondecode(InputStream input) Decodes a value from the input stream.encode(String value, OutputStream output) Encodes the given value and writes it to the output stream.
-
Method Details
-
encode
Encodes the given value and writes it to the output stream.Odd-length values are left-padded with '0' to align to byte boundaries.
- Specified by:
encodein interfaceCodec<String>- Parameters:
value- the value to encodeoutput- the output stream to write the encoded bytes to- Returns:
- the encode result containing logical count and bytes written
- Throws:
IOException- if an I/O error occurs during encoding
-
decode
Decodes a value from the input stream.- Specified by:
decodein interfaceCodec<String>- Parameters:
input- the input stream to read the encoded bytes from- Returns:
- the decoded value
- Throws:
IOException- if an I/O error occurs during decoding
-