UTF-8 StringBuilder.
This class wraps a standard StringBuilder and provides methods to append
UTF-8 encoded bytes, that are converted into characters.
This class is stateful and up to 4 calls to append(byte) may be needed before
state a character is appended to the string buffer.
The UTF-8 decoding is done by this class and no additional buffers or Readers are used. The algorithm is
fast fail, in that errors are detected as the bytes are appended. However, no exceptions are thrown and
only the hasCodingErrors() method indicates the fast failure, otherwise the coding errors
are replaced and may be returned, unless the build() method is used, which may throw
CharacterCodingException. Already decoded characters may also be appended (e.g. append(char)
making this class suitable for decoding % encoded strings of already decoded characters.
java.nio.charset.Charset s.
| Modifier and Type | Class and Description |
|---|---|
| public static class | |
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final StringBuilder | |
| private int | |
| private boolean | |
| protected int | |
| private static final byte[] | |
| protected static final Logger | |
| public static final char | |
| private static final byte[] | |
| private static final int | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public void | append(char
A decoded character to append c)Implements org. |
| public void | |
| public void | |
| public void | append(byte
An encoded byte to append b)Implements org. |
| public void | append(ByteBuffer
Buffer of encoded bytes to append. The bytes are consumed from the buffer. buf)Overrides default org. |
| public void | append(byte[]
Array of encoded bytes to append b)Overrides default org. |
| public void | append(byte[]
Array of encoded bytes b, int offset into the array offset, int the number of bytes to append from the array. length)Overrides default org. |
| public boolean | |
| public void | |
| protected void | |
| protected void | |
| public String | build()
Implements org. Build the completed string and reset the buffer. |
| protected void | |
| public void | complete()
Complete the appendable, adding a replacement character and coding error if the sequence is not currently complete. |
| public boolean | |
| public boolean | |
| public int | |
| public void | partialReset()
Partially reset the appendable: clear the buffer and clear any errors, but retain the decoding state of any partially decoded sequences. |
| public void | reset()
Implements org. |
| public < The type of the exception thrown X extends Throwable> String | Returns: The complete string.A supplier of a onCodingError)Throwable to use if hasCodingErrors() returns true,
or null for no error actionTake the completely decoded string. |
| public < The type of the exception thrown X extends Throwable> String | Returns: The complete string.A supplier of a onCodingError)Throwable to use if hasCodingErrors() returns true,
or null for no error actionTake the partially decoded string. |
| public String | Returns: The completely decoded string.Get the completely decoded string, which is equivalent to calling |
| public String | |
| public String | Returns: The currently decoded string, excluding any partial sequences appended.Overrides java. |
| _buffer | back to summary |
|---|---|
| pack-priv final StringBuilder _buffer | |
| _codep | back to summary |
|---|---|
| private int _codep | |
| _codingErrors | back to summary |
|---|---|
| private boolean _codingErrors | |
| _state | back to summary |
|---|---|
| protected int _state | |
| BYTE_TABLE | back to summary |
|---|---|
| private static final byte[] BYTE_TABLE | |
| LOG | back to summary |
|---|---|
| protected static final Logger LOG | |
| REPLACEMENT | back to summary |
|---|---|
| public static final char REPLACEMENT | |
| TRANS_TABLE | back to summary |
|---|---|
| private static final byte[] TRANS_TABLE | |
| UTF8_ACCEPT | back to summary |
|---|---|
| private static final int UTF8_ACCEPT | |
| UTF8_REJECT | back to summary |
|---|---|
| private static final int UTF8_REJECT | |
| Utf8StringBuilder | back to summary |
|---|---|
| public Utf8StringBuilder() | |
| Utf8StringBuilder | back to summary |
|---|---|
| public Utf8StringBuilder(int capacity) | |
| Utf8StringBuilder | back to summary |
|---|---|
| protected Utf8StringBuilder(StringBuilder buffer) | |
| append | back to summary |
|---|---|
| public void append(char c) Implements org.
| |
| append | back to summary |
|---|---|
| public void append(String s) | |
| append | back to summary |
|---|---|
| public void append(String s, int offset, int length) | |
| append | back to summary |
|---|---|
| public void append(byte b) Implements org.
| |
| append | back to summary |
|---|---|
| public void append(ByteBuffer buf) Overrides default org.
| |
| append | back to summary |
|---|---|
| public void append(byte[] b) Overrides default org.
| |
| append | back to summary |
|---|---|
| public void append(byte[] b, int offset, int length) Overrides default org.
| |
| append | back to summary |
|---|---|
| public boolean append(byte[] b, int offset, int length, int maxChars) | |
| appendByte | back to summary |
|---|---|
| public void appendByte(byte b) throws IOException | |
| bufferAppend | back to summary |
|---|---|
| protected void bufferAppend(char c) | |
| bufferReset | back to summary |
|---|---|
| protected void bufferReset() | |
| build | back to summary |
|---|---|
| public String build() throws CharacterCodingException Implements org. Doc from org. Build the completed string and reset the buffer.
| |
| checkCharAppend | back to summary |
|---|---|
| protected void checkCharAppend() | |
| complete | back to summary |
|---|---|
| public void complete() Complete the appendable, adding a replacement character and coding error if the sequence is not currently complete. | |
| hasCodingErrors | back to summary |
|---|---|
public boolean hasCodingErrors()
| |
| isComplete | back to summary |
|---|---|
public boolean isComplete()
| |
| length | back to summary |
|---|---|
| public int length() Implements org.
| |
| partialReset | back to summary |
|---|---|
| public void partialReset() Partially reset the appendable: clear the buffer and clear any errors, but retain the decoding state of any partially decoded sequences. | |
| reset | back to summary |
|---|---|
| public void reset() Implements org. Reset the appendable, clearing the buffer, resetting decoding state and clearing any errors.
| |
| takeCompleteString | back to summary |
|---|---|
| public <X extends Throwable> String takeCompleteString(Supplier<X> onCodingError) throws Supplier-:X Take the completely decoded string.
| |
| takePartialString | back to summary |
|---|---|
| public <X extends Throwable> String takePartialString(Supplier<X> onCodingError) throws Supplier-:X Take the partially decoded string.
| |
| toCompleteString | back to summary |
|---|---|
| public String toCompleteString() Get the completely decoded string, which is equivalent to calling
| |
| toPartialString | back to summary |
|---|---|
public String toPartialString()
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | getMessage()
Overrides java. |
| public String |
| Utf8CharacterCodingException | back to summary |
|---|---|
| public Utf8CharacterCodingException() | |
| getMessage | back to summary |
|---|---|
| public String getMessage() Overrides java. Doc from java. Returns the detail message string of this throwable. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a short description of this throwable. The result is the concatenation of:
getLocalizedMessage returns null, then just
the class name is returned.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Utf8IllegalArgumentException | back to summary |
|---|---|
| public Utf8IllegalArgumentException() | |