|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.fudgemsg.UTF8
public class UTF8
Utility to manage UTF-8 encoding.
This includes support for normal UTF-8 instead of the modified UTF-8 encoding used
in the earlier versions of the specification. Implemented from information at
en.wikipedia.org/wiki/UTF-8, and
other methods from ModifiedUTF8Util
.
This class is a static utility with no shared state.
Method Summary | |
---|---|
static String |
decode(byte[] arr)
Decodes a string from a byte array. |
static String |
decode(byte[] arr,
int start,
int length)
Decodes a string from part of a byte array. |
static byte[] |
encode(String str)
Encodes a string into an array. |
static int |
encode(String str,
byte[] arr)
Encodes a string into a supplied array. |
static int |
getLengthBytes(char[] str)
Calculate the length in bytes of a string. |
static int |
getLengthBytes(String str)
Calculate the length in bytes of a string. |
static String |
readString(DataInput is,
int utfLen)
Decodes a string from a DataInput source. |
static int |
writeString(DataOutput os,
String str)
Encodes a string to a DataOutput target. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static int getLengthBytes(String str)
str
- the string to find the length of, not null
public static int getLengthBytes(char[] str)
str
- the string to find the length of, not null
public static int encode(String str, byte[] arr)
getLengthBytes(String)
long for this to succeed.
str
- the string to encode, not nullarr
- the array to encode into
ArrayIndexOutOfBoundsException
- if the target array is not big enoughpublic static byte[] encode(String str)
str
- the string to encode, not null
public static String decode(byte[] arr) throws UTFDataFormatException
arr
- the byte encoding of a string to convert, not null
UTFDataFormatException
- if the source does not contain valid UTF-8public static String decode(byte[] arr, int start, int length) throws UTFDataFormatException
arr
- the byte encoding of a string to convert, not nullstart
- the start index of the UTF-8 string encodinglength
- the number of bytes of UTF-8 data
UTFDataFormatException
- if the array fragment does not contain valid UTF-8public static String readString(DataInput is, int utfLen) throws IOException
DataInput
source.
Note that the methods within DataInput
are designed for modified UTF-8
so can't be used directly with Fudge.
is
- the data sourceutfLen
- the number of bytes of data to read
IOException
- if the underlying source raises one or the data is malformedpublic static int writeString(DataOutput os, String str) throws IOException
DataOutput
target.
Note that the methods within DataOutput
are designed for modified UTF-8
so can't be used directly with Fudge.
os
- the data targetstr
- the string to encode
IOException
- if the target raises one
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |