|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.are.common.Utils
public final class Utils
The Utils
class provides a variety of utility methods used by other ARE classes.
Field Summary | |
---|---|
static java.lang.String |
COPYRIGHT
Copyright for class bytecode |
static java.lang.String |
lineSep
Line separator character |
Method Summary | |
---|---|
static boolean |
classImplementsInterface(java.lang.Class theClass,
java.lang.String interfaceName,
java.util.logging.Logger logger)
Checks if the given class implements the specified interface |
static java.lang.String |
classNameOnly(java.lang.Class theClass)
Returns only the class name for the given class by removing the package part of the class name. |
static void |
copyFile(java.lang.String srcFileName,
java.lang.String destFileName)
Performs a binary copy of the contents of the source file into the destination file |
static java.util.logging.Logger |
createEmptyLogger()
Creates an empty logger, with no log handlers. |
static java.util.logging.Logger |
createLogger(java.lang.String packageName,
java.lang.String logFileName,
int maxSize,
int maxNumber)
Creates a new logger with the given specifications |
static boolean |
dirExists(java.lang.String path)
Determines if the directory specified by the given path exists |
static java.lang.String |
ensureDoesNotEndWithSlash(java.lang.String path)
Ensures that the given path does not end with a slash character. |
static java.lang.String |
ensureEndsWithSlash(java.lang.String path)
Ensures that the given path ends with a slash character. |
static java.lang.String |
fileDirFromPath(java.lang.String entirePath)
Returns the directory from the fully qualified path |
static boolean |
fileExists(java.lang.String path)
Determines if the file specified by the given path exists |
static java.lang.String |
fileNameFromPath(java.lang.String entirePath)
Returns the file name from the fully qualified path |
static java.lang.reflect.Constructor |
findConstructor(java.lang.String className)
Finds the empty, no parameter constructor in the given class. |
static java.lang.reflect.Constructor |
findConstructor(java.lang.String className,
java.lang.Class[] args)
Finds the constructor that matches the specified argument signature in the given class. |
static java.lang.reflect.Field |
findField(java.lang.String className,
java.lang.String fieldName)
Finds the specified field in the given class. |
static java.lang.reflect.Method |
findMethod(java.lang.Object invokeObj,
java.lang.String methodName)
Finds the specified method in the given instance of a class |
static java.lang.reflect.Method |
findMethod(java.lang.Object invokeObj,
java.lang.String methodName,
java.lang.Class[] args)
Finds the specified method in the given instance of a class |
static java.lang.reflect.Method |
findMethod(java.lang.String className,
java.lang.String methodName)
Finds the specified method in the given class. |
static java.lang.reflect.Method |
findMethod(java.lang.String className,
java.lang.String methodName,
java.lang.Class[] args)
Finds the specified method in the given class. |
static java.util.logging.Logger |
getGlobalServiceLogger()
Retrieves a reference to the global ARE logger. |
static java.lang.Object |
getInstance(java.lang.String className)
Creates and returns a new instance of the specified class |
static java.util.List |
listFiles(java.lang.String dir)
Returns a list of the contents of the specified directory. |
static java.util.List |
listFilesInDirTree(java.lang.String rootDir,
boolean followSymlinks)
Returns a list of the contents of the specified directory tree. |
static boolean |
parseBoolean(java.lang.String inputBoolean)
Parses a string representation of a boolean, and converts it into a a primitive boolean value. |
static void |
printContents(java.io.PrintStream out,
java.util.Iterator theList,
java.lang.String header,
java.lang.String footer)
Prints the contents of the iterator to the specified stream. |
static void |
printContents(java.io.PrintWriter out,
java.util.Iterator theList,
java.lang.String header,
java.lang.String footer)
Prints the contents of the iterator to the specified writer. |
static void |
printContents(java.io.PrintWriter out,
java.util.Iterator theList,
java.lang.String header,
java.lang.String footer,
java.lang.String encoding)
Prints the contents of the iterator to the specified writer. |
static java.util.List |
readFile(java.lang.String fileName,
java.lang.String encoding)
Reads the contents of the file, interpreting its contents using the specified character encoding. |
static java.lang.String[] |
trimAll(java.lang.String[] inputList)
Trims each string in the given array. |
static void |
writeFile(java.lang.String fileName,
java.lang.String encoding,
java.util.List contents)
Writes the specified contents to the specified file using the provided character encoding. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String COPYRIGHT
public static final java.lang.String lineSep
Method Detail |
---|
public static boolean fileExists(java.lang.String path)
path
- The file path
true
if the file exists, false
if it does notpublic static boolean dirExists(java.lang.String path)
path
- The directory path
true
if the directory exists, false
if it does notpublic static java.lang.String ensureEndsWithSlash(java.lang.String path)
path
- The path to ensure ends with a slash
public static java.lang.String ensureDoesNotEndWithSlash(java.lang.String path)
path
- The path to ensure does not end with a slash
public static java.lang.String[] trimAll(java.lang.String[] inputList)
java.lang.String.trim
method on each
element in the array.
inputList
- The array of strings to trim
public static java.lang.String classNameOnly(java.lang.Class theClass)
theClass
- The class to retrieve the name of
public static java.lang.String fileNameFromPath(java.lang.String entirePath)
entirePath
- The path to return the file name from
public static java.lang.String fileDirFromPath(java.lang.String entirePath)
entirePath
- The path to return the directory from
public static java.util.List listFiles(java.lang.String dir)
dir
- The directory to list the contents of
public static java.util.List listFilesInDirTree(java.lang.String rootDir, boolean followSymlinks)
rootDir
- The directory tree rootfollowSymlinks
- Whether or not symbolic links are followed. This is
only applicable for symbolic links to directories.
public static boolean parseBoolean(java.lang.String inputBoolean)
inputBoolean
- The string representation of a boolean
true
or false
) based on the input stringpublic static void copyFile(java.lang.String srcFileName, java.lang.String destFileName)
srcFileName
- The file to copy fromdestFileName
- The file to copy intopublic static java.util.List readFile(java.lang.String fileName, java.lang.String encoding)
fileName
- The name of the file to readencoding
- The character encoding of the text in the file. If no encoding
needs to be specified, null
can be passed for this
parameter, in which case the system property file.encoding
will be used.
public static void writeFile(java.lang.String fileName, java.lang.String encoding, java.util.List contents)
fileName
- The name of the file to write the contents toencoding
- The character encoding of the text written to the file. If no encoding
needs to be specified, null
can be passed for this
parameter, in which case the system property file.encoding
will be used.contents
- A list of the contents to write to the file. The contents
will be written in the precise order they are stored in the list.public static java.lang.Object getInstance(java.lang.String className) throws java.lang.Exception
className
- The name of the class to create a new instance of
java.lang.Exception
- If an exception occurs while instantiating a new
instance of the specified class.public static void printContents(java.io.PrintStream out, java.util.Iterator theList, java.lang.String header, java.lang.String footer)
out
- The stream to print totheList
- An iterator over a list of items to print to the streamheader
- An optional header that is printed to the stream prior to
printing the items in the iterator. If no header is desired,
null
can be passed for this parameter.footer
- An optional footer that is printed to the stream after
printing the items in the iterator. If no footer is desired,
null
can be passed for this parameter.public static void printContents(java.io.PrintWriter out, java.util.Iterator theList, java.lang.String header, java.lang.String footer)
out
- The writer to print totheList
- An iterator over a list of items to print to the writerheader
- An optional header that is printed to the writer prior to
printing the items in the iterator. If no header is desired,
null
can be passed for this parameter.footer
- An optional footer that is printed to the writer after
printing the items in the iterator. If no footer is desired,
null
can be passed for this parameter.public static void printContents(java.io.PrintWriter out, java.util.Iterator theList, java.lang.String header, java.lang.String footer, java.lang.String encoding)
out
- The writer to print totheList
- An iterator over a list of items to print to the writerheader
- An optional header that is printed to the writer prior to
printing the items in the iterator. If no header is desired,
null
can be passed for this parameter.footer
- An optional footer that is printed to the writer after
printing the items in the iterator. If no footer is desired,
null
can be passed for this parameter.encoding
- The encoding of the text that will be written to the writerpublic static java.lang.reflect.Field findField(java.lang.String className, java.lang.String fieldName) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchFieldException
className
- The class namefieldName
- The name of the field to find in the class
java.lang.ClassNotFoundException
- If the specified class cannot be found
java.lang.SecurityException
- If the field cannot be accessed
java.lang.NoSuchFieldException
- If the field cannot be found in the specified classpublic static java.lang.reflect.Constructor findConstructor(java.lang.String className) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException
className
- The class name
java.lang.ClassNotFoundException
- If the specified class cannot be found
java.lang.SecurityException
- If the constructor cannot be accessed
java.lang.NoSuchMethodException
- If the constructor cannot be found in the specified classpublic static java.lang.reflect.Constructor findConstructor(java.lang.String className, java.lang.Class[] args) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException
className
- The class nameargs
- The constructor argument types
java.lang.ClassNotFoundException
- If the specified class cannot be found
java.lang.SecurityException
- If the constructor cannot be accessed
java.lang.NoSuchMethodException
- If the constructor cannot be found in the specified classpublic static java.lang.reflect.Method findMethod(java.lang.String className, java.lang.String methodName) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException
className
- The class namemethodName
- The name of the method to find in the class
java.lang.ClassNotFoundException
- If the specified class cannot be found
java.lang.SecurityException
- If the method cannot be accessed
java.lang.NoSuchMethodException
- If the method cannot be found in the specified classpublic static java.lang.reflect.Method findMethod(java.lang.String className, java.lang.String methodName, java.lang.Class[] args) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException
className
- The class namemethodName
- The name of the method to find in the classargs
- The method argument types
java.lang.ClassNotFoundException
- If the specified class cannot be found
java.lang.SecurityException
- If the method cannot be accessed
java.lang.NoSuchMethodException
- If the method cannot be found in the specified classpublic static java.lang.reflect.Method findMethod(java.lang.Object invokeObj, java.lang.String methodName) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException
invokeObj
- The object to use when searching for the methodmethodName
- The name of the method to find in the class
java.lang.ClassNotFoundException
- If the specified class cannot be found
java.lang.SecurityException
- If the method cannot be accessed
java.lang.NoSuchMethodException
- If the method cannot be found in the specified classpublic static java.lang.reflect.Method findMethod(java.lang.Object invokeObj, java.lang.String methodName, java.lang.Class[] args) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException
invokeObj
- The object to use when searching for the methodmethodName
- The name of the method to find in the classargs
- The method argument types
java.lang.ClassNotFoundException
- If the specified class cannot be found
java.lang.SecurityException
- If the method cannot be accessed
java.lang.NoSuchMethodException
- If the method cannot be found in the specified classpublic static boolean classImplementsInterface(java.lang.Class theClass, java.lang.String interfaceName, java.util.logging.Logger logger)
theClass
- The class to checkinterfaceName
- The interface to check forlogger
- Optional. Logger (fine) for class interface details
true
if the class implements the interface, false
if it does notpublic static java.util.logging.Logger getGlobalServiceLogger()
public static java.util.logging.Logger createEmptyLogger()
public static java.util.logging.Logger createLogger(java.lang.String packageName, java.lang.String logFileName, int maxSize, int maxNumber)
packageName
- Package name associated with the loggerlogFileName
- Name of the log filemaxSize
- Maximum size, in bytes, that the log file can grow tomaxNumber
- Maximum number of log files that can be created before
the oldest log file is deleted.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |