public class UTF8ByteCounter
extends java.lang.Object
UTF8ByteCounter
is used to count the number of UTF-8 bytes in a
given string or a character stream. Due to the differences in byte
representation when reading invalid surrogate pairs from an input stream and
when converting a string to corresponding UTF-8 bytes using
String.getBytes("utf-8")
, an object of this class must be
initialized by providing UTF8ByteCounter.Type.INPUT_STREAM
or
UTF8ByteCounter.Type.STRING_TO_UTF8
accordingly.Modifier and Type | Class and Description |
---|---|
static class |
UTF8ByteCounter.Type
Represents the type of a UTF8ByteCounter object.
|
Constructor and Description |
---|
UTF8ByteCounter(UTF8ByteCounter.Type type)
Initialized a
UTF8ByteCounter with the specified type. |
Modifier and Type | Method and Description |
---|---|
void |
consume(char c)
Consumes a character.
|
static int |
count(java.lang.String s)
Counts the number of UTF-8 bytes using counting methond
UTF8ByteCounter.Type.STRING_TO_UTF8 . |
static int |
count(java.lang.String s,
UTF8ByteCounter.Type type)
Counts the number of UTF-8 encoded bytes for a given string using the
specified counting type.
|
int |
getCount()
Returns the number of UTF-8 bytes in the characters consumed.
|
public UTF8ByteCounter(UTF8ByteCounter.Type type)
UTF8ByteCounter
with the specified type.type
- type of the UTF8ByteCounterpublic static int count(java.lang.String s, UTF8ByteCounter.Type type)
s
- String to be countedtype
- Counting methods
.public static int count(java.lang.String s)
UTF8ByteCounter.Type.STRING_TO_UTF8
. The valued returned is
equivalent to s.getBytes("utf-8")
.s
- String to be counteds
public int getCount()
public void consume(char c)
c
- character to be consumed.