Package org.eclipse.jetty.util
Class TypeUtil
- java.lang.Object
-
- org.eclipse.jetty.util.TypeUtil
-
public class TypeUtil extends Object
TYPE Utilities. Provides various static utility methods for manipulating types and their string representations.- Since:
- Jetty 4.1
-
-
Constructor Summary
Constructors Constructor Description TypeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> List<T>asList(T[] a)Array to List.static Objectcall(Class<?> oClass, String methodName, Object obj, Object[] arg)static Objectconstruct(Class<?> klass, Object[] arguments)static Objectconstruct(Class<?> klass, Object[] arguments, Map<String,Object> namedArgMap)static byteconvertHexDigit(byte c)static intconvertHexDigit(char c)static intconvertHexDigit(int c)static voiddump(Class<?> c)static voiddump(ClassLoader cl)static byte[]fromHexString(String s)static Class<?>fromName(String name)Class from a canonical name for a type.static URIgetLocationOfClass(Class<?> clazz)static booleanisFalse(Object o)static booleanisTrue(Object o)static byte[]parseBytes(String s, int base)static intparseInt(byte[] b, int offset, int length, int base)Parse an int from a byte array of ascii characters.static intparseInt(String s, int offset, int length, int base)Parse an int from a substring.static voidtoHex(byte b, Appendable buf)static voidtoHex(int value, Appendable buf)static voidtoHex(long value, Appendable buf)static StringtoHexString(byte b)static StringtoHexString(byte[] b)static StringtoHexString(byte[] b, int offset, int length)static StringtoName(Class<?> type)Canonical name for a type.static StringtoString(byte[] bytes, int base)static ObjectvalueOf(Class<?> type, String value)Convert String value to instance.static ObjectvalueOf(String type, String value)Convert String value to instance.
-
-
-
Field Detail
-
NO_ARGS
public static final Class<?>[] NO_ARGS
-
CR
public static final int CR
- See Also:
- Constant Field Values
-
LF
public static final int LF
- See Also:
- Constant Field Values
-
-
Method Detail
-
asList
public static <T> List<T> asList(T[] a)
Array to List.Works like
Arrays.asList(Object...), but handles null arrays.- Type Parameters:
T- the array and list entry type- Parameters:
a- the array to convert to a list- Returns:
- a list backed by the array.
-
fromName
public static Class<?> fromName(String name)
Class from a canonical name for a type.- Parameters:
name- A class or type name.- Returns:
- A class , which may be a primitive TYPE field..
-
toName
public static String toName(Class<?> type)
Canonical name for a type.- Parameters:
type- A class , which may be a primitive TYPE field.- Returns:
- Canonical name.
-
valueOf
public static Object valueOf(Class<?> type, String value)
Convert String value to instance.- Parameters:
type- The class of the instance, which may be a primitive TYPE field.value- The value as a string.- Returns:
- The value as an Object.
-
valueOf
public static Object valueOf(String type, String value)
Convert String value to instance.- Parameters:
type- classname or type (eg int)value- The value as a string.- Returns:
- The value as an Object.
-
parseInt
public static int parseInt(String s, int offset, int length, int base) throws NumberFormatException
Parse an int from a substring. Negative numbers are not handled.- Parameters:
s- Stringoffset- Offset within stringlength- Length of integer or -1 for remainder of stringbase- base of the integer- Returns:
- the parsed integer
- Throws:
NumberFormatException- if the string cannot be parsed
-
parseInt
public static int parseInt(byte[] b, int offset, int length, int base) throws NumberFormatExceptionParse an int from a byte array of ascii characters. Negative numbers are not handled.- Parameters:
b- byte arrayoffset- Offset within stringlength- Length of integer or -1 for remainder of stringbase- base of the integer- Returns:
- the parsed integer
- Throws:
NumberFormatException- if the array cannot be parsed into an integer
-
parseBytes
public static byte[] parseBytes(String s, int base)
-
toString
public static String toString(byte[] bytes, int base)
-
convertHexDigit
public static byte convertHexDigit(byte c)
- Parameters:
c- An ASCII encoded character 0-9 a-f A-F- Returns:
- The byte value of the character 0-16.
-
convertHexDigit
public static int convertHexDigit(char c)
- Parameters:
c- An ASCII encoded character 0-9 a-f A-F- Returns:
- The byte value of the character 0-16.
-
convertHexDigit
public static int convertHexDigit(int c)
- Parameters:
c- An ASCII encoded character 0-9 a-f A-F- Returns:
- The byte value of the character 0-16.
-
toHex
public static void toHex(byte b, Appendable buf)
-
toHex
public static void toHex(int value, Appendable buf) throws IOException- Throws:
IOException
-
toHex
public static void toHex(long value, Appendable buf) throws IOException- Throws:
IOException
-
toHexString
public static String toHexString(byte b)
-
toHexString
public static String toHexString(byte[] b)
-
toHexString
public static String toHexString(byte[] b, int offset, int length)
-
fromHexString
public static byte[] fromHexString(String s)
-
dump
public static void dump(Class<?> c)
-
dump
public static void dump(ClassLoader cl)
-
call
public static Object call(Class<?> oClass, String methodName, Object obj, Object[] arg) throws InvocationTargetException, NoSuchMethodException
-
construct
public static Object construct(Class<?> klass, Object[] arguments) throws InvocationTargetException, NoSuchMethodException
-
construct
public static Object construct(Class<?> klass, Object[] arguments, Map<String,Object> namedArgMap) throws InvocationTargetException, NoSuchMethodException
-
isTrue
public static boolean isTrue(Object o)
- Parameters:
o- Object to test for true- Returns:
- True if passed object is not null and is either a Boolean with value true or evaluates to a string that evaluates to true.
-
isFalse
public static boolean isFalse(Object o)
- Parameters:
o- Object to test for false- Returns:
- True if passed object is not null and is either a Boolean with value false or evaluates to a string that evaluates to false.
-
-