Package org.aesh.terminal.io
Class Encoder
java.lang.Object
org.aesh.terminal.io.Encoder
- All Implemented Interfaces:
Consumer<int[]>
Encodes int arrays (unicode code points) to byte arrays using a specified charset.
- Author:
- Ståle W. Pedersen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(int[] input) Encode an array of Unicode code points and send the resulting bytes to the output consumer.voidEncode a String directly to bytes, bypassing the int[] intermediary.voidsetCharset(Charset charset) Set the charset to use for encoding.static CharBuffertoCharBuffer(int[] input) Convert an array of Unicode code points to a CharBuffer.
-
Constructor Details
-
Encoder
Create a new Encoder with the specified charset and output consumer.- Parameters:
charset- the charset to use for encoding, or null for the default charsetout- the consumer to receive encoded byte arrays
-
-
Method Details
-
setCharset
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. -
accept
Encode a String directly to bytes, bypassing the int[] intermediary. For UTF-8 with ASCII-only strings (the common case for ANSI sequences), this converts directly from String chars to byte[] in a single pass.- Parameters:
s- the string to encode
-
toCharBuffer
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
-