Package org.apache.vinci.transport.util
Class UTFConverter
- java.lang.Object
-
- org.apache.vinci.transport.util.UTFConverter
-
public class UTFConverter extends java.lang.ObjectProvides utility methods for Java string <==> UTF-8 conversion. We don't use the default Java methods for UTF-8 since they are non-standard and not as efficient as this implementation.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFALSE_VALUEstatic java.lang.StringTRUE_VALUE
-
Constructor Summary
Constructors Modifier Constructor Description privateUTFConverter()Private Constructor
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcalculateUTFLength(char[] inputArray, int startOffset, int endOffset)Calculate the UTF-8 length of a character array.static intcalculateUTFLength(java.lang.String inputString)Calculate the UTF-8 length of a Java String.static byte[]convertStringToUTF(char[] inputArray, int startOffset, int endOffset)Convert a String from a character array to UTF-8.static intconvertStringToUTF(char[] inputArray, int startOffset, int endOffset, byte[] resultArray)Convert the given char[] input into UTF-8 and place in the destination buffer.static byte[]convertStringToUTF(java.lang.String inputString)Convert a Java String to UTF-8.static intconvertStringToUTF(java.lang.String inputString, byte[] resultArray)Convert the given char[] input into UTF-8 and place in the destination buffer.static booleanconvertUTFToBool(byte[] bytearr)Convert the UTF-8 contents of a byte array to a boolean.static doubleconvertUTFToDouble(byte[] bytearr)Convert the UTF-8 contents of a byte array to a double.static floatconvertUTFToFloat(byte[] bytearr)Convert the UTF-8 contents of a byte array of UTF-8 bytes to a float.static intconvertUTFToInt(byte[] bytearr)Convert the UTF-8 contents of a byte array to an int.static longconvertUTFToLong(byte[] bytearr)Convert the UTF-8 contents of a byte array to a long.static java.lang.StringconvertUTFToString(byte[] bytearr)Convert the UTF-8 contents of a byte array to a Java String.static intconvertUTFToString(byte[] bytearr, int beginOffset, int inputLength, char[] result)Convert the UTF-8 contents of a byte array to a Java String.
-
-
-
Field Detail
-
TRUE_VALUE
public static final java.lang.String TRUE_VALUE
- See Also:
- Constant Field Values
-
FALSE_VALUE
public static final java.lang.String FALSE_VALUE
- See Also:
- Constant Field Values
-
-
Method Detail
-
convertUTFToFloat
public static float convertUTFToFloat(byte[] bytearr) throws java.io.UTFDataFormatException, java.lang.NumberFormatExceptionConvert the UTF-8 contents of a byte array of UTF-8 bytes to a float.- Parameters:
bytearr- Array of bytes.- Returns:
- float.
- Throws:
java.io.UTFDataFormatException- if the UTF-8 is encoded improperlyjava.lang.NumberFormatException- if conversion to a number can't be done
-
convertUTFToDouble
public static double convertUTFToDouble(byte[] bytearr) throws java.io.UTFDataFormatException, java.lang.NumberFormatExceptionConvert the UTF-8 contents of a byte array to a double.- Parameters:
bytearr- Array of bytes.- Returns:
- double.
- Throws:
java.io.UTFDataFormatException- if the UTF-8 is encoded improperlyjava.lang.NumberFormatException- if conversion to a number can't be done
-
convertUTFToBool
public static boolean convertUTFToBool(byte[] bytearr) throws java.io.UTFDataFormatExceptionConvert the UTF-8 contents of a byte array to a boolean.- Parameters:
bytearr- Array of bytes.- Returns:
- boolean.
- Throws:
java.io.UTFDataFormatException- if the UTF-8 is encoded improperly
-
convertUTFToInt
public static int convertUTFToInt(byte[] bytearr) throws java.io.UTFDataFormatException, java.lang.NumberFormatExceptionConvert the UTF-8 contents of a byte array to an int.- Parameters:
bytearr- Array of bytes.- Returns:
- int.
- Throws:
java.io.UTFDataFormatException- if the UTF-8 is encoded improperlyjava.lang.NumberFormatException- if conversion to a number can't be done
-
convertUTFToLong
public static long convertUTFToLong(byte[] bytearr) throws java.io.UTFDataFormatException, java.lang.NumberFormatExceptionConvert the UTF-8 contents of a byte array to a long.- Parameters:
bytearr- Array of bytes.- Returns:
- long.
- Throws:
java.io.UTFDataFormatException- if the UTF-8 is encoded improperlyjava.lang.NumberFormatException- if conversion to a number can't be done
-
convertUTFToString
public static java.lang.String convertUTFToString(byte[] bytearr) throws java.io.UTFDataFormatExceptionConvert the UTF-8 contents of a byte array to a Java String.- Parameters:
bytearr- Array of bytes.- Returns:
- String.
- Throws:
java.io.UTFDataFormatException- if the UTF-8 is encoded improperly
-
convertUTFToString
public static int convertUTFToString(byte[] bytearr, int beginOffset, int inputLength, char[] result) throws java.io.UTFDataFormatExceptionConvert the UTF-8 contents of a byte array to a Java String.- Parameters:
bytearr- Array of bytes.beginOffset- Start offest to data in byte array.inputLength- Length of the data to convert.result- Character array containing the converted characters.- Returns:
- The length of the converted characters.
- Throws:
java.io.UTFDataFormatException- if the UTF-8 is encoded improperly
-
convertStringToUTF
public static byte[] convertStringToUTF(java.lang.String inputString)
Convert a Java String to UTF-8.- Parameters:
inputString- String to convert.- Returns:
- array of UTF-8 bytes.
-
convertStringToUTF
public static byte[] convertStringToUTF(char[] inputArray, int startOffset, int endOffset)Convert a String from a character array to UTF-8.- Parameters:
inputArray- Array of characters to convert.startOffset- Start offset in character array.endOffset- One past the last character in the array.- Returns:
- A byte array with the converted result.
-
calculateUTFLength
public static int calculateUTFLength(char[] inputArray, int startOffset, int endOffset)Calculate the UTF-8 length of a character array.- Parameters:
inputArray- Array of characters.startOffset- Start offset of the data in the character array.endOffset- One past the last character in the array.- Returns:
- The number of bytes in the UTF-8 representation.
-
calculateUTFLength
public static int calculateUTFLength(java.lang.String inputString)
Calculate the UTF-8 length of a Java String.- Parameters:
inputString- The String to calculate the length of.- Returns:
- The number of bytes in the UTF-8 representation.
-
convertStringToUTF
public static int convertStringToUTF(char[] inputArray, int startOffset, int endOffset, byte[] resultArray)Convert the given char[] input into UTF-8 and place in the destination buffer. This method assumes the destination buffer is big enough to hold the output.- Parameters:
inputArray- Array of characters to convert.startOffset- Start offset in character array.endOffset- One past the last character in the array.resultArray- Byte array containing the converted characters.- Returns:
- The number of characters in the UTF-8 representation.
-
convertStringToUTF
public static int convertStringToUTF(java.lang.String inputString, byte[] resultArray)Convert the given char[] input into UTF-8 and place in the destination buffer. This method assumes the destination buffer is big enough to hold the output.- Parameters:
inputString- String to convert.resultArray- Byte array containing the converted characters.- Returns:
- the number of characters in the UTF-8 representation.
-
-