public class Utility extends Object
| Constructor and Description |
|---|
Utility() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
delete(File file)
Delete a file or directory.
|
static String |
escapeSingleQuote(String inputString)
This method will escape any single quotes found in the input string
and return the escaped string.
|
static boolean |
isNumeric(String s)
Check string s is numeric.
|
static void |
loadProperties(Properties props,
Class clazz,
String resourceName)
Load properties from a resource.
|
static void |
logMemoryStats(String msg)
Log statistics on memory to stderr.
|
static Iterator |
parseCommaList(String list)
Parse a list.
|
static void |
redirect(InputStream in,
OutputStream out)
Asynchronously redirect an input stream onto an output stream.
|
public static void loadProperties(Properties props, Class clazz, String resourceName)
You typically use this to merge properties for your application into the System properties by calling this method as follows:
Utility.loadProperties(System.getProperties(), MyClass.class, "MyClass.properties");This adds the properties from the file
MyClass.properties (which must exist in the same directory as the
file MyClass.class, whether in the filesystem or in a jar) into
the system properties. You can then fetch these properties from anywhere in
your program with System.getProperty(String),
Integer.getInteger, etc.
You can also use the method to load properties into a newly created
properties object that you provide. This keeps your properties separate, but
then you have to pass a properties object all over the place, and you can't
take advantage of non-String properties through methods like
Long#getLong(String), etc.
props - The properties object to load.clazz - The class used to locate the resource.resourceName - The name of the resource.public static Iterator parseCommaList(String list)
list - The list to parse.public static void redirect(InputStream in, OutputStream out)
in - Input stream to redirect.out - Where to redirect in.public static void logMemoryStats(String msg)
msg - Text to include in log.public static boolean isNumeric(String s)
s - Text to be checked.public static boolean delete(File file)
file - File, directory, or other filesystem artifact to delete.public static String escapeSingleQuote(String inputString)
inputString - The string to be escaped.Copyright © 1999–2017 Apache OODT. All rights reserved.