Top Description Inners Fields Constructors Methods
org.jboss.marshalling

public final Class UTFUtils

extends Object
Class Inheritance
Imports
java.io.IOException, .UTFDataFormatException, .EOFException

Handy utility methods for dealing with strings in the modified UTF-8 format.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final UTFUtils.BytesHolder
private static final String
private static final String
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

the length
getLongUTFLength
(final String
the string
s
)

Get the number of bytes used by the modified UTF-8 encoded form of the given string.

public static int

Returns:

the length
getShortUTFLength
(final String
the string
s
)

Get the number of bytes used by the modified UTF-8 encoded form of the given string.

public static String

Returns:

the string
readUTFBytes
(final ByteInput
the byte source
input
,
final int
the number of characters to read
len
)

Read the given number of characters from the given byte input.

public static String

Returns:

the string
readUTFBytesByByteCount
(final ByteInput
the byte source
input
,
final long
the number of bytes to read
len
)

Read the given number of characters from the given byte input.

private static int
readUTFChar(final ByteInput input)

public static String

Returns:

the string
readUTFZBytes
(final ByteInput
the input
input
)

Read a null-terminated modified UTF-8 string from the given byte input.

public static void
writeUTFBytes(final ByteOutput
the output to write to
output
,
final String
the string
s
)

Write the modified UTF-8 form of the given string to the given output.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BYTES_HOLDERback to summary
private static final UTFUtils.BytesHolder BYTES_HOLDER
INVALID_BYTEback to summary
private static final String INVALID_BYTE
MALFORMEDback to summary
private static final String MALFORMED
UTF_BUFS_BYTE_CNTback to summary
private static final int UTF_BUFS_BYTE_CNT
UTF_BUFS_CHAR_CNTback to summary
private static final int UTF_BUFS_CHAR_CNT

Constructor Detail

UTFUtilsback to summary
private UTFUtils()

Method Detail

getLongUTFLengthback to summary
public static long getLongUTFLength(final String s)

Get the number of bytes used by the modified UTF-8 encoded form of the given string.

Parameters
s:String

the string

Returns:long

the length

See Also
java.io.DataInput#readUTF()
getShortUTFLengthback to summary
public static int getShortUTFLength(final String s) throws UTFDataFormatException

Get the number of bytes used by the modified UTF-8 encoded form of the given string. If the length is greater than 65536, an exception is thrown.

Parameters
s:String

the string

Returns:int

the length

Exceptions
UTFDataFormatException:
if the string is longer than 65536 characters
See Also
java.io.DataInput#readUTF()
readUTFBytesback to summary
public static String readUTFBytes(final ByteInput input, final int len) throws IOException

Read the given number of characters from the given byte input. The length given is in characters, NOT in bytes.

Parameters
input:ByteInput

the byte source

len:int

the number of characters to read

Returns:String

the string

Exceptions
IOException:
if an I/O error occurs
See Also
java.io.DataInput#readUTF()
readUTFBytesByByteCountback to summary
public static String readUTFBytesByByteCount(final ByteInput input, final long len) throws IOException

Read the given number of characters from the given byte input. The length given is in bytes.

Parameters
input:ByteInput

the byte source

len:long

the number of bytes to read

Returns:String

the string

Exceptions
IOException:
if an I/O error occurs
See Also
java.io.DataInput#readUTF()
readUTFCharback to summary
private static int readUTFChar(final ByteInput input) throws IOException
readUTFZBytesback to summary
public static String readUTFZBytes(final ByteInput input) throws IOException

Read a null-terminated modified UTF-8 string from the given byte input. Bytes are read until a 0 is found or until the end of the stream, whichever comes first.

Parameters
input:ByteInput

the input

Returns:String

the string

Exceptions
IOException:
if an I/O error occurs
See Also
java.io.DataInput#readUTF()
writeUTFBytesback to summary
public static void writeUTFBytes(final ByteOutput output, final String s) throws IOException

Write the modified UTF-8 form of the given string to the given output.

Parameters
output:ByteOutput

the output to write to

s:String

the string

Exceptions
IOException:
if an I/O error occurs
See Also
java.io.DataOutput#writeUTF(String)
org.jboss.marshalling back to summary

private final Class UTFUtils.BytesHolder

extends ThreadLocal<byte[]>
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected byte[]
initialValue()

Overrides java.lang.ThreadLocal.initialValue.

Returns the current thread's "initial value" for this thread-local variable.
Inherited from java.lang.ThreadLocal:
getremovesetwithInitial

Constructor Detail

BytesHolderback to summary
private BytesHolder()

Method Detail

initialValueback to summary
protected byte[] initialValue()

Overrides java.lang.ThreadLocal.initialValue.

Doc from java.lang.ThreadLocal.initialValue.

Returns the current thread's "initial value" for this thread-local variable. This method will be invoked the first time a thread accesses the variable with the get method, unless the thread previously invoked the set method, in which case the initialValue method will not be invoked for the thread. Normally, this method is invoked at most once per thread, but it may be invoked again in case of subsequent invocations of remove followed by get.

Returns:byte[]

the initial value for this thread-local