JBoss Marshalling 1.3.0.CR9

org.jboss.marshalling
Class UTFUtils

java.lang.Object
  extended by org.jboss.marshalling.UTFUtils

public final class UTFUtils
extends Object

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


Method Summary
static long getLongUTFLength(String s)
          Get the number of bytes used by the modified UTF-8 encoded form of the given string.
static int getShortUTFLength(String s)
          Get the number of bytes used by the modified UTF-8 encoded form of the given string.
static String readUTFBytes(ByteInput input, int len)
          Read the given number of characters from the given byte input.
static String readUTFBytesByByteCount(ByteInput input, long len)
          Read the given number of characters from the given byte input.
static String readUTFZBytes(ByteInput input)
          Read a null-terminated modified UTF-8 string from the given byte input.
static void writeUTFBytes(ByteOutput output, String s)
          Write the modified UTF-8 form of the given string to the given output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getShortUTFLength

public static int getShortUTFLength(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 - the string
Returns:
the length
Throws:
UTFDataFormatException - if the string is longer than 65536 characters
See Also:
DataInput.readUTF()

getLongUTFLength

public static long getLongUTFLength(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,
                                 String s)
                          throws IOException
Write the modified UTF-8 form of the given string to the given output.

Parameters:
output - the output to write to
s - the string
Throws:
IOException - if an I/O error occurs
See Also:
DataOutput.writeUTF(String)

readUTFBytes

public static String readUTFBytes(ByteInput input,
                                  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 - the byte source
len - the number of characters to read
Returns:
the string
Throws:
IOException - if an I/O error occurs
See Also:
DataInput.readUTF()

readUTFBytesByByteCount

public static String readUTFBytesByByteCount(ByteInput input,
                                             long len)
                                      throws IOException
Read the given number of characters from the given byte input. The length given is in bytes.

Parameters:
input - the byte source
len - the number of bytes to read
Returns:
the string
Throws:
IOException - if an I/O error occurs
See Also:
DataInput.readUTF()

readUTFZBytes

public static String readUTFZBytes(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 - the input
Returns:
the string
Throws:
IOException - if an I/O error occurs
See Also:
DataInput.readUTF()

JBoss Marshalling 1.3.0.CR9

Copyright © 2011 JBoss, a division of Red Hat, Inc.