Package org.aesh.terminal.io
Class Decoder
java.lang.Object
org.aesh.terminal.io.Decoder
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidsetCharset(Charset charset) Set the charset to use for decoding.voidsetConsumer(Consumer<int[]> inputHandler) Set the consumer that will receive decoded code point arrays.voidwrite(byte[] data) Decode a byte array and send the resulting code points to the consumer.voidwrite(byte[] data, int start, int len) Decode a portion of a byte array and send the resulting code points to the consumer.
-
Constructor Details
-
Decoder
Create a new Decoder with the specified charset and consumer.- Parameters:
charset- the charset to use for decoding, or null for the default charsetonChar- the consumer to receive decoded code point arrays
-
Decoder
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 charsetonChar- the consumer to receive decoded code point arrays- Throws:
IllegalArgumentException- if initialSize is less than 2
-
-
Method Details
-
setCharset
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 decodestart- the starting offset in the arraylen- the number of bytes to decode
-
setConsumer
Set the consumer that will receive decoded code point arrays.- Parameters:
inputHandler- the consumer to receive decoded output
-