org.objectweb.jac.core.utils
Class Lib

java.lang.Object
  extended byorg.objectweb.jac.core.utils.Lib

public class Lib
extends Object

Lib is a container class for various utility method used by org.objectweb.jac. None of these methods is attached to any particular jac files but should be, in an ideal world, provided by the JDK.


Constructor Summary
Lib()
           
 
Method Summary
static Object deserialize(byte[] buf)
          Deserialize an object from an array of bytes.
static Object deserialize(byte[] data, Class oisClass)
          Deserialize an object from an array of bytes.
static Object[] enumToArray(Enumeration enum)
          Transform object stored as a enumeration object into an array of object.
static void exec(String command)
          Execute a command in a process and dump its standard output and error.
static Class[] getClasses(Object[] objs)
          Get classes.
static String[] getFieldsName(Object src)
          Get fields name.
static Object[] getFieldsValue(Object src)
          Get fields value.
static Object[] getFieldsValue(Object src, String[] fieldsName)
          Get fields value.
static byte[] loadByteCodeFromFile(String dirName, String fileName)
          Return the byte code contained in file dirName.
static void printArray(Object o)
          Recursively pretty prints an array.
static byte[] serialize(Object src)
          Serialize an object into an array of bytes.
static byte[] serialize(Object src, Class oosClass)
          Serialize an object into an array of bytes.
static void setFieldsValue(Object src, String[] fieldsName, Object[] fieldsValue)
          Set fields value.
static Hashtable stringArrayToHashtable(String[] strs)
          Store a string array into a hashtable.
static String stringsEnumToString(Enumeration stringsEnum)
          Transform strings stored as a enumeration object into a space-separated string.
static String[] stringsEnumToStringArray(Enumeration stringsEnum)
          Transform strings stored as a enumeration object into an array of strings.
static String[] stringToStringArray(String str)
          Transform a string composed of substrings separated by spaces into an array composed of the substrings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Lib

public Lib()
Method Detail

exec

public static void exec(String command)
Execute a command in a process and dump its standard output and error.

Parameters:
command - the command to execute

stringsEnumToString

public static String stringsEnumToString(Enumeration stringsEnum)
Transform strings stored as a enumeration object into a space-separated string.

Parameters:
stringsEnum - the enumeration object containing the strings
Returns:
a space-separated string composed of the string contained in stringsEnum

stringsEnumToStringArray

public static String[] stringsEnumToStringArray(Enumeration stringsEnum)
Transform strings stored as a enumeration object into an array of strings.

Parameters:
stringsEnum - the enumeration object containing the strings
Returns:
an array of strings composed of the string contained in stringsEnum

enumToArray

public static Object[] enumToArray(Enumeration enum)
Transform object stored as a enumeration object into an array of object.

Parameters:
enum - the enumeration object containing the objects
Returns:
an array of objects composed of the objects contained in enum

stringToStringArray

public static String[] stringToStringArray(String str)
Transform a string composed of substrings separated by spaces into an array composed of the substrings.

Parameters:
str - the string composed of substrings separated by spaces
Returns:
an array composed of the substrings

stringArrayToHashtable

public static Hashtable stringArrayToHashtable(String[] strs)
Store a string array into a hashtable.

Parameters:
strs - the string array
Returns:
the hashtable

loadByteCodeFromFile

public static byte[] loadByteCodeFromFile(String dirName,
                                          String fileName)
Return the byte code contained in file dirName.fileName.class

Parameters:
dirName - the directory where the file is stored
fileName - the file name
Returns:
the byte code

serialize

public static byte[] serialize(Object src)
Serialize an object into an array of bytes.

Parameters:
src - the object to serialize
Returns:
an array of bytes

serialize

public static byte[] serialize(Object src,
                               Class oosClass)
Serialize an object into an array of bytes.

Parameters:
src - the object to serialize
oosClass - the subclass of ObjectOutputStream to use for serializing src
Returns:
an array of bytes

deserialize

public static Object deserialize(byte[] buf)
Deserialize an object from an array of bytes.

Parameters:
buf - the array of bytes
Returns:
the object or null if a error has been encountered

deserialize

public static Object deserialize(byte[] data,
                                 Class oisClass)
Deserialize an object from an array of bytes.

Parameters:
data - the array of bytes
oisClass - the subclass of ObjectInputStream to use for deserializing src
Returns:
the object or null if a error has been encountered

getFieldsName

public static String[] getFieldsName(Object src)
Get fields name.

Parameters:
src - the source object containing the fields
Returns:
the fields name as an array of strings

getFieldsValue

public static Object[] getFieldsValue(Object src)
Get fields value.

Parameters:
src - the source object containing the fields
Returns:
the fields value as an array of objects

getFieldsValue

public static Object[] getFieldsValue(Object src,
                                      String[] fieldsName)
Get fields value.

Parameters:
src - the source object containing the fields
fieldsName - the fields name
Returns:
the fields value as an array of objects

setFieldsValue

public static void setFieldsValue(Object src,
                                  String[] fieldsName,
                                  Object[] fieldsValue)
Set fields value.

Parameters:
src - the source object
fieldsName - the fields name
fieldsValue - the fields value

getClasses

public static Class[] getClasses(Object[] objs)
Get classes.

Parameters:
objs - the objects as an array
Returns:
the array of classes where each element is the class of the corresponding object

printArray

public static void printArray(Object o)
Recursively pretty prints an array.

Parameters:
o - the array