Class Encoder

java.lang.Object
org.aesh.terminal.io.Encoder
All Implemented Interfaces:
Consumer<int[]>

public class Encoder extends Object implements Consumer<int[]>
Encodes int arrays (unicode code points) to byte arrays using a specified charset.
Author:
Ståle W. Pedersen
  • Constructor Details

    • Encoder

      public Encoder(Charset charset, Consumer<byte[]> out)
      Create a new Encoder with the specified charset and output consumer.
      Parameters:
      charset - the charset to use for encoding, or null for the default charset
      out - the consumer to receive encoded byte arrays
  • Method Details

    • setCharset

      public void setCharset(Charset charset)
      Set the charset to use for encoding.
      Parameters:
      charset - the charset to use, ignored if null
    • accept

      public void accept(int[] input)
      Encode an array of Unicode code points and send the resulting bytes to the output consumer.
      Specified by:
      accept in interface Consumer<int[]>
      Parameters:
      input - the code points to encode
    • toCharBuffer

      public static CharBuffer toCharBuffer(int[] input)
      Convert an array of Unicode code points to a CharBuffer. Handles surrogate pairs for code points outside the Basic Multilingual Plane.
      Parameters:
      input - the code points to convert
      Returns:
      a CharBuffer containing the character representation