Class StreamCodePointStringCodec

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

public class StreamCodePointStringCodec extends Object implements Codec<String>
A codec for variable-length character strings that reads all remaining bytes from the stream.

Unlike FixedCodePointStringCodec, which reads a fixed number of code points, 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.

Example usage:


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

    • encode

      public EncodeResult encode(String value, OutputStream output) throws IOException
      Encodes the given value and writes it to the output stream.
      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:
      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:
      IOException - if an I/O error occurs during decoding