|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.h2.util.Utils
public class Utils
This utility class contains miscellaneous functions.
Field Summary | |
---|---|
static byte[] |
EMPTY_BYTES
An 0-size byte array. |
static int[] |
EMPTY_INT_ARRAY
An 0-size int array. |
Method Summary | |
---|---|
static java.lang.Object |
callMethod(java.lang.Object instance,
java.lang.String methodName,
java.lang.Object... params)
Calls an instance method via reflection. |
static java.lang.Object |
callStaticMethod(java.lang.String classAndMethod,
java.lang.Object... params)
Calls a static method via reflection. |
static byte[] |
cloneByteArray(byte[] b)
Create a new byte array and copy all the data. |
static int |
compareNotNull(byte[] data1,
byte[] data2)
Compare the contents of two byte arrays. |
static boolean |
compareSecure(byte[] test,
byte[] good)
Compare two byte arrays. |
static byte[] |
copy(byte[] source,
byte[] target)
Copy the contents of the source array to the target array. |
static java.lang.Object |
deserialize(byte[] data)
De-serialize the byte array to an object. |
static int |
getByteArrayHash(byte[] value)
Calculate the hash code of the given byte array. |
static java.lang.Object |
getField(java.lang.Object instance,
java.lang.String fieldName)
Returns a static field. |
static int |
getMemoryFree()
Get the free memory in KB. |
static long |
getMemoryMax()
Get the maximum memory in KB. |
static int |
getMemoryUsed()
Get the used memory in KB. |
static java.lang.Class<?> |
getNonPrimitiveClass(java.lang.Class<?> clazz)
Convert primitive class names to java.lang.* class names. |
static byte[] |
getResource(java.lang.String name)
Get a resource from the resource map. |
static java.lang.Object |
getStaticField(java.lang.String classAndField)
Returns a static field. |
static int |
hashCode(java.lang.Object o)
Calculate the hash code of the given object. |
static int |
indexOf(byte[] bytes,
byte[] pattern,
int start)
Calculate the index of the first occurrence of the pattern in the byte array, starting with the given index. |
static boolean |
isClassPresent(java.lang.String fullyQualifiedClassName)
Returns true if the class is present in the current class loader. |
static java.lang.Class<?> |
loadUserClass(java.lang.String className)
Load a class, but check if it is allowed to load this class first. |
static byte[] |
newBytes(int len)
Create an array of bytes with the given size. |
static java.lang.Object |
newInstance(java.lang.String className,
java.lang.Object... params)
Creates a new instance. |
static int[] |
newIntArray(int len)
Create an int array with the given size. |
static long[] |
newLongArray(int len)
Create a long array with the given size. |
static long |
readLong(byte[] buff,
int pos)
Read a long value from the byte array at the given position. |
static byte[] |
serialize(java.lang.Object obj)
Serialize the object to a byte array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte[] EMPTY_BYTES
public static final int[] EMPTY_INT_ARRAY
Method Detail |
---|
public static long readLong(byte[] buff, int pos)
buff
- the byte arraypos
- the position
public static int indexOf(byte[] bytes, byte[] pattern, int start)
bytes
- the byte arraypattern
- the patternstart
- the start index from where to search
public static int getByteArrayHash(byte[] value)
value
- the byte array
public static boolean compareSecure(byte[] test, byte[] good)
test
- the first arraygood
- the second array
public static int compareNotNull(byte[] data1, byte[] data2)
data1
- the first byte array (must not be null)data2
- the second byte array (must not be null)
public static byte[] copy(byte[] source, byte[] target)
source
- the source arraytarget
- the target array
public static byte[] cloneByteArray(byte[] b)
b
- the byte array (may not be null)
public static byte[] serialize(java.lang.Object obj)
obj
- the object to serialize
public static java.lang.Object deserialize(byte[] data)
data
- the byte array
SQLException
public static int hashCode(java.lang.Object o)
o
- the object
public static int getMemoryUsed()
public static int getMemoryFree()
public static long getMemoryMax()
public static byte[] newBytes(int len)
len
- the number of bytes requested
java.lang.OutOfMemoryError
public static int[] newIntArray(int len)
len
- the number of bytes requested
public static long[] newLongArray(int len)
len
- the number of bytes requested
public static java.lang.Class<?> loadUserClass(java.lang.String className)
className
- the name of the class
public static byte[] getResource(java.lang.String name) throws java.io.IOException
name
- the name of the resource
java.io.IOException
public static java.lang.Object callStaticMethod(java.lang.String classAndMethod, java.lang.Object... params) throws java.lang.Exception
classAndMethod
- a string with the entire class and method name, eg.
"java.lang.System.gc"params
- the method parameters
java.lang.Exception
public static java.lang.Object callMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Object... params) throws java.lang.Exception
instance
- the instance on which the call is donemethodName
- a string with the method nameparams
- the method parameters
java.lang.Exception
public static java.lang.Object newInstance(java.lang.String className, java.lang.Object... params) throws java.lang.Exception
className
- a string with the entire class, eg. "java.lang.Integer"params
- the constructor parameters
java.lang.Exception
public static java.lang.Object getStaticField(java.lang.String classAndField) throws java.lang.Exception
classAndField
- a string with the entire class and field name
java.lang.Exception
public static java.lang.Object getField(java.lang.Object instance, java.lang.String fieldName) throws java.lang.Exception
instance
- the instance on which the call is donefieldName
- the field name
java.lang.Exception
public static boolean isClassPresent(java.lang.String fullyQualifiedClassName)
fullyQualifiedClassName
- a string with the entire class name, eg.
"java.lang.System"
public static java.lang.Class<?> getNonPrimitiveClass(java.lang.Class<?> clazz)
clazz
- the class (for example: int)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |