Top Description Inners Constructors Methods
org.apache.derby.iapi.util

public final Class UTF8Util

extends Object
Class Inheritance
Imports
java.io.EOFException, .IOException, .InputStream, .UTFDataFormatException, org.apache.derby.iapi.services.io.InputStreamUtil

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
java.io.DataInput

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
UTF8Util.SkipCount

Helper class to hold skip counts; one for chars and one for bytes.

Constructor Summary

AccessConstructor and Description
private
UTF8Util()

This class cannot be instantiated.

Method Summary

Modifier and TypeMethod and Description
private static final UTF8Util.SkipCount

Returns:

A long array with counts; the characters skipped at position CHAR_COUNT, the bytes skipped at position BYTE_COUNT. Note that the number of characters skipped may be smaller than the requested number.
internalSkip
(final InputStream
byte stream with UTF-8 encoded characters
in
,
final long
the number of characters to skip
charsToSkip
)

Skip characters in the stream.

public static final long

Returns:

The number of bytes skipped.
skipFully
(InputStream
byte stream with UTF-8 encoded characters
in
,
long
number of characters to skip
charsToSkip
)

Skip the requested number of characters from the stream.

public static final long

Returns:

The number of characters skipped.
skipUntilEOF
(InputStream
byte stream with UTF-8 encoded characters
in
)

Skip until the end-of-stream is reached.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

UTF8Utilback to summary
private UTF8Util()

This class cannot be instantiated.

Method Detail

internalSkipback to summary
private static final UTF8Util.SkipCount internalSkip(final InputStream in, final 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:InputStream

byte stream with UTF-8 encoded characters

charsToSkip:long

the number of characters to skip

Returns:UTF8Util.SkipCount

A long array with counts; the characters skipped at position CHAR_COUNT, the bytes skipped at position BYTE_COUNT. Note that the number of characters skipped may be smaller than the requested number.

Exceptions
IOException:
if reading from the stream fails
UTFDataFormatException:
if an invalid UTF-8 encoding is detected
skipFullyback to summary
public static final long skipFully(InputStream in, long charsToSkip) throws EOFException, IOException

Skip the requested number of characters from the stream.

Parameters
in:InputStream

byte stream with UTF-8 encoded characters

charsToSkip:long

number of characters to skip

Returns:long

The number of bytes skipped.

Exceptions
EOFException:
if end-of-stream is reached before the requested number of characters are skipped
IOException:
if reading from the stream fails
UTFDataFormatException:
if an invalid UTF-8 encoding is detected
skipUntilEOFback to summary
public static final long skipUntilEOF(InputStream in) throws IOException

Skip until the end-of-stream is reached.

Parameters
in:InputStream

byte stream with UTF-8 encoded characters

Returns:long

The number of characters skipped.

Exceptions
IOException:
if reading from the stream fails
UTFDataFormatException:
if an invalid UTF-8 encoding is detected
org.apache.derby.iapi.util back to summary

private final Class UTF8Util.SkipCount

extends Object
Class Inheritance

Helper class to hold skip counts; one for chars and one for bytes.

Field Summary

Modifier and TypeField and Description
private final long
byteCount

Number of bytes skipped.

private final long
charCount

Number of characters skipped.

Constructor Summary

AccessConstructor and Description
pack-priv
SkipCount(long
number of characters
charCount
,
long
number of bytes
byteCount
)

Creates a holder for the specified skip counts.

Method Summary

Modifier and TypeMethod and Description
pack-priv long
pack-priv long
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

byteCountback to summary
private final long byteCount

Number of bytes skipped.

charCountback to summary
private final long charCount

Number of characters skipped.

Constructor Detail

SkipCountback to summary
pack-priv SkipCount(long charCount, long byteCount)

Creates a holder for the specified skip counts.

Parameters
charCount:long

number of characters

byteCount:long

number of bytes

Method Detail

bytesSkippedback to summary
pack-priv long bytesSkipped()
charsSkippedback to summary
pack-priv long charsSkipped()