Package org.apache.derby.iapi.util
Class UTF8Util
java.lang.Object
org.apache.derby.iapi.util.UTF8Util
Utility methods for handling UTF-8 encoded byte streams.
Note that when the skip
methods mention detection of invalid
UTF-8 encodings, it only checks the first byte of a character. For multibyte
encodings, the second and third byte are not checked for correctness, just
skipped and ignored.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Helper class to hold skip counts; one for chars and one for bytes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static final UTF8Util.SkipCount
internalSkip
(InputStream in, long charsToSkip) Skip characters in the stream.static final long
skipFully
(InputStream in, long charsToSkip) Skip the requested number of characters from the stream.static final long
Skip until the end-of-stream is reached.
-
Constructor Details
-
UTF8Util
private UTF8Util()This class cannot be instantiated.
-
-
Method Details
-
skipUntilEOF
Skip until the end-of-stream is reached.- Parameters:
in
- byte stream with UTF-8 encoded characters- Returns:
- The number of characters skipped.
- Throws:
IOException
- if reading from the stream failsUTFDataFormatException
- if an invalid UTF-8 encoding is detected
-
skipFully
public static final long skipFully(InputStream in, long charsToSkip) throws EOFException, IOException Skip the requested number of characters from the stream.- Parameters:
in
- byte stream with UTF-8 encoded characterscharsToSkip
- number of characters to skip- Returns:
- The number of bytes skipped.
- Throws:
EOFException
- if end-of-stream is reached before the requested number of characters are skippedIOException
- if reading from the stream failsUTFDataFormatException
- if an invalid UTF-8 encoding is detected
-
internalSkip
private static final UTF8Util.SkipCount internalSkip(InputStream in, long charsToSkip) throws IOException Skip characters in the stream.Note that a smaller number than requested might be skipped if the end-of-stream is reached before the specified number of characters has been decoded. It is up to the caller to decide if this is an error or not. For instance, when determining the character length of a stream,
Long.MAX_VALUE
could be passed as the requested number of characters to skip.- Parameters:
in
- byte stream with UTF-8 encoded characterscharsToSkip
- the number of characters to skip- Returns:
- A long array with counts; the characters skipped at position
CHAR_COUNT
, the bytes skipped at positionBYTE_COUNT
. Note that the number of characters skipped may be smaller than the requested number. - Throws:
IOException
- if reading from the stream failsUTFDataFormatException
- if an invalid UTF-8 encoding is detected
-