Package org.jboss.marshalling
Class UTFUtils
- java.lang.Object
-
- org.jboss.marshalling.UTFUtils
-
public final class UTFUtils extends java.lang.Object
Handy utility methods for dealing with strings in the modified UTF-8 format.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
UTFUtils.BytesHolder
-
Field Summary
Fields Modifier and Type Field Description private static UTFUtils.BytesHolder
BYTES_HOLDER
private static java.lang.String
INVALID_BYTE
private static java.lang.String
MALFORMED
private static int
UTF_BUFS_BYTE_CNT
private static int
UTF_BUFS_CHAR_CNT
-
Constructor Summary
Constructors Modifier Constructor Description private
UTFUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
getLongUTFLength(java.lang.String s)
Get the number of bytes used by the modified UTF-8 encoded form of the given string.static int
getShortUTFLength(java.lang.String s)
Get the number of bytes used by the modified UTF-8 encoded form of the given string.static java.lang.String
readUTFBytes(ByteInput input, int len)
Read the given number of characters from the given byte input.static java.lang.String
readUTFBytesByByteCount(ByteInput input, long len)
Read the given number of characters from the given byte input.private static int
readUTFChar(ByteInput input)
static java.lang.String
readUTFZBytes(ByteInput input)
Read a null-terminated modified UTF-8 string from the given byte input.static void
writeUTFBytes(ByteOutput output, java.lang.String s)
Write the modified UTF-8 form of the given string to the given output.
-
-
-
Field Detail
-
INVALID_BYTE
private static final java.lang.String INVALID_BYTE
- See Also:
- Constant Field Values
-
MALFORMED
private static final java.lang.String MALFORMED
- See Also:
- Constant Field Values
-
UTF_BUFS_CHAR_CNT
private static final int UTF_BUFS_CHAR_CNT
- See Also:
- Constant Field Values
-
UTF_BUFS_BYTE_CNT
private static final int UTF_BUFS_BYTE_CNT
- See Also:
- Constant Field Values
-
BYTES_HOLDER
private static final UTFUtils.BytesHolder BYTES_HOLDER
-
-
Method Detail
-
getShortUTFLength
public static int getShortUTFLength(java.lang.String s) throws java.io.UTFDataFormatException
Get the number of bytes used by the modified UTF-8 encoded form of the given string. If the length is greater than65536
, an exception is thrown.- Parameters:
s
- the string- Returns:
- the length
- Throws:
java.io.UTFDataFormatException
- if the string is longer than65536
characters- See Also:
DataInput.readUTF()
-
getLongUTFLength
public static long getLongUTFLength(java.lang.String s)
Get the number of bytes used by the modified UTF-8 encoded form of the given string.- Parameters:
s
- the string- Returns:
- the length
- See Also:
DataInput.readUTF()
-
writeUTFBytes
public static void writeUTFBytes(ByteOutput output, java.lang.String s) throws java.io.IOException
Write the modified UTF-8 form of the given string to the given output.- Parameters:
output
- the output to write tos
- the string- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
DataOutput.writeUTF(String)
-
readUTFBytes
public static java.lang.String readUTFBytes(ByteInput input, int len) throws java.io.IOException
Read the given number of characters from the given byte input. The length given is in characters, NOT in bytes.- Parameters:
input
- the byte sourcelen
- the number of characters to read- Returns:
- the string
- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
DataInput.readUTF()
-
readUTFBytesByByteCount
public static java.lang.String readUTFBytesByByteCount(ByteInput input, long len) throws java.io.IOException
Read the given number of characters from the given byte input. The length given is in bytes.- Parameters:
input
- the byte sourcelen
- the number of bytes to read- Returns:
- the string
- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
DataInput.readUTF()
-
readUTFZBytes
public static java.lang.String readUTFZBytes(ByteInput input) throws java.io.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
- the input- Returns:
- the string
- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
DataInput.readUTF()
-
readUTFChar
private static int readUTFChar(ByteInput input) throws java.io.IOException
- Throws:
java.io.IOException
-
-