Class Decoder

java.lang.Object
org.aesh.terminal.io.Decoder

public class Decoder extends Object
Decodes byte arrays into Unicode code point arrays using a specified charset.

This decoder handles multi-byte character sequences and surrogate pairs, converting raw bytes from terminal input into code points for processing.

Code is based on Julien Viet's BinaryDecoder in termd.

Author:
Ståle W. Pedersen
  • Constructor Summary

    Constructors
    Constructor
    Description
    Decoder(int initialSize, Charset charset, Consumer<int[]> onChar)
    Create a new Decoder with the specified initial buffer size, charset, and consumer.
    Decoder(Charset charset, Consumer<int[]> onChar)
    Create a new Decoder with the specified charset and consumer.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Set the charset to use for decoding.
    void
    setConsumer(Consumer<int[]> inputHandler)
    Set the consumer that will receive decoded code point arrays.
    void
    write(byte[] data)
    Decode a byte array and send the resulting code points to the consumer.
    void
    write(byte[] data, int start, int len)
    Decode a portion of a byte array and send the resulting code points to the consumer.

    Methods inherited from class java.lang.Object

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

    • Decoder

      public Decoder(Charset charset, Consumer<int[]> onChar)
      Create a new Decoder with the specified charset and consumer.
      Parameters:
      charset - the charset to use for decoding, or null for the default charset
      onChar - the consumer to receive decoded code point arrays
    • Decoder

      public Decoder(int initialSize, Charset charset, Consumer<int[]> onChar)
      Create a new Decoder with the specified initial buffer size, charset, and consumer.
      Parameters:
      initialSize - the initial size of the character buffer (must be at least 2)
      charset - the charset to use for decoding, or null for the default charset
      onChar - the consumer to receive decoded code point arrays
      Throws:
      IllegalArgumentException - if initialSize is less than 2
  • Method Details

    • setCharset

      public void setCharset(Charset charset)
      Set the charset to use for decoding.
      Parameters:
      charset - the charset to use
    • write

      public void write(byte[] data)
      Decode a byte array and send the resulting code points to the consumer.
      Parameters:
      data - the bytes to decode
    • write

      public void write(byte[] data, int start, int len)
      Decode a portion of a byte array and send the resulting code points to the consumer.
      Parameters:
      data - the byte array containing data to decode
      start - the starting offset in the array
      len - the number of bytes to decode
    • setConsumer

      public void setConsumer(Consumer<int[]> inputHandler)
      Set the consumer that will receive decoded code point arrays.
      Parameters:
      inputHandler - the consumer to receive decoded output