public final class Toolkit extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
Toolkit.IFileFilter
This is the interface to select files with below.
|
Constructor and Description |
---|
Toolkit() |
Modifier and Type | Method and Description |
---|---|
static String |
classNameToPackageName(String className)
Takes the name of a class and returns the package name for the class.
|
static String |
cleanFilePath(String path) |
static void |
copyFile(File in,
File out) |
static boolean |
createFile(File file) |
static void |
deleteFile(File file,
int maxRetryCount)
Deletes all the files recursively and then the directories recursively.
|
static void |
deleteFiles(File file,
String... extensions)
Deletes all the files in a directory with one of the specified extensions.
|
static String |
dotToSlash(String name)
This method replaces the .
|
static <E> E |
executeMethod(Object object,
String methodName,
Object[] parameters) |
static void |
findFiles(File file,
Toolkit.IFileFilter filter,
List<File> list)
Finds files on the file system below the directory specified recursively using the selection criteria supplied in the IFileFilter
parameter.
|
static double |
format(double d,
int precision)
Formats a double to the required precision.
|
static String |
format(String string,
int precision)
Formats a string to the desired precision.
|
static ByteArrayOutputStream |
getContents(File file)
Reads the contents of the file and returns the contents in a byte array form.
|
static ByteArrayOutputStream |
getContents(InputStream inputStream)
Reads the contents of the file and returns the contents in a byte array form.
|
static File |
getOrCreateDirectory(File file)
Gets a single directory.
|
static String |
getStringContents(InputStream inputStream) |
static <T> T[] |
getUniqueValues(T t)
Returns an array of values that are defined as being a unique combination for the entity by using the Unique annotation for the
class.
|
static <E> E |
getValue(Class<E> klass,
Object object,
String name)
Returns the value of the field specified from the object specified.
|
static Long |
hash(Object... objects)
Builds a hash from an array of objects.
|
static Long |
hash(String string)
Simple, fast hash function to generate quite unique hashes from strings(i.e.
|
static boolean |
isDigits(String string)
Verifies that all the characters in a string are digits, ie.
|
static String |
replaceAll(String aInput,
String aOldPattern,
String aNewPattern)
If Java 1.4 is unavailable, the following technique may be used.
|
static void |
setContents(File file,
byte[] bytes)
Writes the contents of a byte array to a file.
|
static String |
slashToDot(String name)
This method replaces the / in the byte code name with .
|
static String |
stripWhitespace(String string)
Removes any whitespace from the string.
|
public static Long hash(String string)
string
- the string to generate the hash frompublic static Long hash(Object... objects)
objects
- the objects to build the hash frompublic static String slashToDot(String name)
name
- the byte code name of a classpublic static String dotToSlash(String name)
name
- the name of the class or packagepublic static String classNameToPackageName(String className)
className
- the name of the class fully qualifiedpublic static String stripWhitespace(String string)
string
- the string to remove whitespace frompublic static <E> E getValue(Class<E> klass, Object object, String name)
E
- the type to returnklass
- the class to get the value forobject
- the object to get the field value fromname
- the name of the field in the objectpublic static <E> E executeMethod(Object object, String methodName, Object[] parameters)
public static void deleteFile(File file, int maxRetryCount)
file
- the directory or file to deletemaxRetryCount
- the number of times to retry to delete the filepublic static void deleteFiles(File file, String... extensions)
file
- the file to delete or the directory to delete files inextensions
- the extensions of files to deletepublic static void findFiles(File file, Toolkit.IFileFilter filter, List<File> list)
file
- the file to start looking fromfilter
- the filter to select files withlist
- the list of files to add the selected files topublic static ByteArrayOutputStream getContents(File file)
file
- the file to read the contents frompublic static ByteArrayOutputStream getContents(InputStream inputStream)
inputStream
- the file to read the contents frompublic static String getStringContents(InputStream inputStream)
public static void setContents(File file, byte[] bytes)
file
- the file to write tobytes
- the byte data to writepublic static double format(double d, int precision)
d
- the double to formatprecision
- the precision for the resultpublic static String format(String string, int precision)
string
- the string to format to a precisionprecision
- the precision of the resultpublic static <T> T[] getUniqueValues(T t)
T
- the type of object to be inspected for unique fieldst
- the object t inspect for unique field combinationspublic static String replaceAll(String aInput, String aOldPattern, String aNewPattern)
aInput
- is the original String which may contain substring aOldPatternaOldPattern
- is the non-empty substring which is to be replacedaNewPattern
- is the replacement for aOldPatternpublic static boolean createFile(File file)
public static File getOrCreateDirectory(File file)
file
- the directory that is requestedFile
or null
if something went wrong.public static boolean isDigits(String string)
string
- the string to verify for digit dataCopyright © 2016–2020. All rights reserved.