Class FixedHexStringCodec

java.lang.Object
io.bytestreams.codec.core.FixedHexStringCodec
All Implemented Interfaces:
Codec<String>

public class FixedHexStringCodec extends Object implements Codec<String>
A codec for fixed-length hexadecimal strings.

Odd-length values are left-padded with '0' to align to byte boundaries. Encode accepts both uppercase and lowercase hex digits. Decode always returns uppercase.


 Codec<String> codec = Codecs.hex(4);
 
  • Method Details

    • encode

      public EncodeResult encode(String value, OutputStream output) throws IOException
      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:
      encode in interface Codec<String>
      Parameters:
      value - the value to encode
      output - the output stream to write the encoded bytes to
      Returns:
      the encode result containing logical count and bytes written
      Throws:
      IllegalArgumentException - if the value length exceeds the configured length
      IOException - if an I/O error occurs during encoding
    • decode

      public String decode(InputStream input) throws IOException
      Decodes a value from the input stream.
      Specified by:
      decode in interface Codec<String>
      Parameters:
      input - the input stream to read the encoded bytes from
      Returns:
      the decoded value
      Throws:
      EOFException - if the stream has insufficient bytes
      IOException - if an I/O error occurs during decoding