lejos.charset
Class UTF8Decoder

java.lang.Object
  extended by lejos.charset.UTF8Decoder
All Implemented Interfaces:
CharsetDecoder

public class UTF8Decoder
extends Object
implements CharsetDecoder


Constructor Summary
UTF8Decoder()
           
 
Method Summary
 int decode(byte[] source, int offset, int limit)
          Calculates a Unicode codepoint from the bytes in the buffer.
 int estimateByteCount(byte[] source, 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UTF8Decoder

public UTF8Decoder()
Method Detail

decode

public int decode(byte[] source,
                  int offset,
                  int limit)
Description copied from interface: CharsetDecoder
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.

Specified by:
decode in interface CharsetDecoder
Parameters:
source - the array of bytes
offset - the index of the first byte to be read
limit - the index after the last byte that is to be read
Returns:
the Unicode codepoint or '?'

estimateByteCount

public int estimateByteCount(byte[] source,
                             int offset,
                             int limit)
Description copied from interface: CharsetDecoder
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).

Specified by:
estimateByteCount in interface CharsetDecoder
Parameters:
source - the array of bytes
offset - the index of the first byte to be read
limit - the index after the last byte that is to be read
Returns:
the estimated number of bytes

getMaxCharLength

public int getMaxCharLength()
Specified by:
getMaxCharLength in interface CharsetDecoder