lejos.charset
Interface CharsetDecoder
- All Known Implementing Classes:
- Latin1Decoder, UTF8Decoder
public interface CharsetDecoder
Method Summary |
int |
decode(byte[] buf,
int offset,
int limit)
Calculates a Unicode codepoint from the bytes in the buffer. |
int |
estimateByteCount(byte[] buf,
int offset,
int limit)
Calculates the number of bytes that are needed to decode a full Unicode codepoint
at the given position in the byte array. |
int |
getMaxCharLength()
|
getMaxCharLength
int getMaxCharLength()
decode
int decode(byte[] buf,
int offset,
int limit)
- Calculates a Unicode codepoint from the bytes in the buffer.
If the bytes in the buffer cannot be decoded, because they are
malformed or because there is not enough data, then the '?' character
should be returned.
- Parameters:
buf
- the array of bytesoffset
- the index of the first byte to be readlimit
- the index after the last byte that is to be read
- Returns:
- the Unicode codepoint or '?'
estimateByteCount
int estimateByteCount(byte[] buf,
int offset,
int limit)
- Calculates the number of bytes that are needed to decode a full Unicode codepoint
at the given position in the byte array.
The function must handle three cases:
a) the given array does contain the full encoding of a Unicode codepoint
b) the given data is too short to be the encoding of a Unicode codepoint
c) the given data is malformed
In cases a) and c), the function must return the number of
bytes that must be skipped after the decoding of the character.
In case b), the function should return an estimation of the
number of bytes needed to decode the next Unicode codepoint.
Yet, this must not be an overestimation. In case b), the return
value should be at least (limit - offset + 1).
- Parameters:
buf
- the array of bytesoffset
- the index of the first byte to be readlimit
- the index after the last byte that is to be read
- Returns:
- the estimated number of bytes