public class Utils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Object |
callConstructor(java.lang.Class<?> cls,
java.lang.Object... args)
Construct a class object with the given arguments
|
static java.lang.Double |
convertToDouble(java.lang.Object obj) |
static void |
copyStream(java.io.InputStream input,
java.io.OutputStream output) |
static java.io.File |
createTempDir() |
static java.io.File |
createTempDir(java.io.File parent) |
static void |
croak(java.lang.String message,
int exitCode)
Print the message and then exit with the given exit code
|
static boolean |
equals(java.lang.Object a,
java.lang.Object b)
Equivalent to Object.equals except that it handles nulls.
|
static java.io.File |
findFilefromDir(java.io.File dir,
java.lang.String fn) |
static java.lang.String |
flattenToString(java.util.Collection<?> collection,
java.lang.String delimiter) |
static <T> T |
ifNull(T value,
T defaultValue)
Return the value itself if it is non-null, otherwise return the default value
|
static java.lang.Object |
invokeStaticMethod(java.lang.ClassLoader loader,
java.lang.String className,
java.lang.String methodName,
java.lang.Object... args) |
static boolean |
isCronExpressionValid(java.lang.String cronExpression,
org.joda.time.DateTimeZone timezone) |
static boolean |
isValidPort(int port)
Tests whether a port is valid or not
|
static void |
mergeStringList(java.util.List<java.lang.String> destinationList,
java.util.List<java.lang.String> sourceList)
Merge elements in Source List into the Destination List
|
static void |
mergeTypeClassPaths(java.util.List<java.lang.String> destinationPaths,
java.util.List<java.lang.String> sourcePaths,
java.lang.String rootPath)
Merge the absolute paths of source paths into the list of destination paths
|
static <T> T |
nonNull(T t)
Return the object if it is non-null, otherwise throw an exception
|
static org.quartz.CronExpression |
parseCronExpression(java.lang.String cronExpression,
org.joda.time.DateTimeZone timezone) |
static long |
parseMemString(java.lang.String strMemSize) |
static java.util.ArrayList<java.lang.String> |
runProcess(java.lang.String... commands)
Run a sequence of commands
|
static void |
unzip(java.util.zip.ZipFile source,
java.io.File dest) |
static void |
zip(java.io.File input,
java.io.File output) |
static void |
zipFolderContent(java.io.File folder,
java.io.File output) |
public static boolean equals(java.lang.Object a,
java.lang.Object b)
public static <T> T nonNull(T t)
T - The type of the objectt - The objectjava.lang.IllegalArgumentException - if the object is nullpublic static java.io.File findFilefromDir(java.io.File dir,
java.lang.String fn)
public static <T> T ifNull(T value,
T defaultValue)
T - The type of the objectvalue - The objectdefaultValue - default value if object == nullpublic static void croak(java.lang.String message,
int exitCode)
message - The message to printexitCode - The exit codepublic static boolean isValidPort(int port)
public static java.io.File createTempDir()
public static java.io.File createTempDir(java.io.File parent)
public static void zip(java.io.File input,
java.io.File output)
throws java.io.IOException
java.io.IOExceptionpublic static void zipFolderContent(java.io.File folder,
java.io.File output)
throws java.io.IOException
java.io.IOExceptionpublic static void unzip(java.util.zip.ZipFile source,
java.io.File dest)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String flattenToString(java.util.Collection<?> collection,
java.lang.String delimiter)
public static java.lang.Double convertToDouble(java.lang.Object obj)
public static java.lang.Object callConstructor(java.lang.Class<?> cls,
java.lang.Object... args)
cls - The classargs - The argumentspublic static java.lang.Object invokeStaticMethod(java.lang.ClassLoader loader,
java.lang.String className,
java.lang.String methodName,
java.lang.Object... args)
throws java.lang.ClassNotFoundException,
java.lang.SecurityException,
java.lang.NoSuchMethodException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundExceptionjava.lang.SecurityExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalArgumentExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionpublic static void copyStream(java.io.InputStream input,
java.io.OutputStream output)
throws java.io.IOException
java.io.IOExceptionpublic static long parseMemString(java.lang.String strMemSize)
strMemSize - : memory string in the format such as 1G, 500M, 3000K, 5000public static org.quartz.CronExpression parseCronExpression(java.lang.String cronExpression,
org.joda.time.DateTimeZone timezone)
cronExpression: - A cron expression is a string separated by white space, to provide a
parser and evaluator for Quartz cron expressions.public static boolean isCronExpressionValid(java.lang.String cronExpression,
org.joda.time.DateTimeZone timezone)
public static java.util.ArrayList<java.lang.String> runProcess(java.lang.String... commands)
throws java.lang.InterruptedException,
java.io.IOException
commands - sequence of commandsjava.lang.InterruptedExceptionjava.io.IOExceptionpublic static void mergeTypeClassPaths(java.util.List<java.lang.String> destinationPaths,
java.util.List<java.lang.String> sourcePaths,
java.lang.String rootPath)
destinationPaths - the path list which the source paths will be merged intosourcePaths - source pathsrootPath - defined root path for source paths when they are not absolute pathpublic static void mergeStringList(java.util.List<java.lang.String> destinationList,
java.util.List<java.lang.String> sourceList)
destinationList - the list which the source elements will be merged intosourceList - source List