kom.tools.util
Class Util

java.lang.Object
  |
  +--kom.tools.util.Util

public class Util
extends java.lang.Object

Some helpful utilities


Constructor Summary
Util()
           
 
Method Summary
static boolean copyFile(java.io.File from, java.io.File to)
          Copies a file from one location to another
static boolean copyFile(java.lang.String from, java.lang.String to)
          Copies a file from one location to another
static java.lang.String currTime()
          Creates a string representing current time
static boolean equal(java.lang.String s1, java.lang.String s2)
          Compares strings, null-safe
static int getInt(java.lang.String value)
          Gets the value of a string in Integer format
static int getInt(java.lang.String value, int defval)
          Gets the value of a string in Integer format
static long getLong(java.lang.String value, long defval)
          Gets the Long value of the input string
static boolean isNullOrEmpty(java.lang.String str)
          Tests for null or empty string
static void purgeAllFiles(java.lang.String dir)
          Removes all files from a directory
static void purgeFilesWithPrefix(java.lang.String dir, java.lang.String pre)
          Removes all files with a specific prefix from a directory.
static java.lang.String rand()
          Generates a random number in String format
static java.lang.String readLine(java.io.InputStream stream)
          Reads a line from an input stream
static java.lang.String secTime(java.util.Date date)
          Creates a string representing time
static java.lang.String[] string2array(java.lang.String v, java.lang.String d)
          Splits a String at delimiters into a String[] array.
static java.lang.String toFile(java.lang.String name)
          "Sanitizes" a file name
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

isNullOrEmpty

public static boolean isNullOrEmpty(java.lang.String str)
Tests for null or empty string
Parameters:
str - The input string
Returns:
true if the input is null or an empty string

equal

public static final boolean equal(java.lang.String s1,
                                  java.lang.String s2)
Compares strings, null-safe
Parameters:
s1 - First String
s2 - Second String
Returns:
true if both are non-null and s1.equals(s2)

getInt

public static final int getInt(java.lang.String value)
Gets the value of a string in Integer format
Parameters:
value - The string (should be an Integer encoding of a number >= 0)
Returns:
-1 If the number is badly formed or the input is null, otherwise the converted integer.

getInt

public static final int getInt(java.lang.String value,
                               int defval)
Gets the value of a string in Integer format
Parameters:
value - The string (should be an Integer encoding of a number >= 0)
defval - Default value if string could not be parsed
Returns:
defval if the number is badly formed or the input is null, otherwise the converted value.

getLong

public static final long getLong(java.lang.String value,
                                 long defval)
Gets the Long value of the input string
Parameters:
value - The input string (should be a number >=0)
defval - Default value if string could not be parsed
Returns:
defval if the number is badly formed or the input is null, otherwise the converted value.

readLine

public static java.lang.String readLine(java.io.InputStream stream)
Reads a line from an input stream
Parameters:
stream - The input stream
Returns:
The line or null if no more data available.

copyFile

public static boolean copyFile(java.lang.String from,
                               java.lang.String to)
Copies a file from one location to another
Parameters:
from - The source file path
to - The destination path
Returns:
true If the copy action was ok

copyFile

public static boolean copyFile(java.io.File from,
                               java.io.File to)
Copies a file from one location to another
Parameters:
from - The source File
to - The destination File
Returns:
true If the copy action was ok

purgeAllFiles

public static void purgeAllFiles(java.lang.String dir)
Removes all files from a directory
Parameters:
dir - The directory name + any directory separator

purgeFilesWithPrefix

public static void purgeFilesWithPrefix(java.lang.String dir,
                                        java.lang.String pre)
Removes all files with a specific prefix from a directory.
Parameters:
dir - The directory (including any directory separator)
pre - The prefix for the file name

toFile

public static java.lang.String toFile(java.lang.String name)
"Sanitizes" a file name
Parameters:
name - The tentative file name
Returns:
the name string, with any '*' or ' ' replaced by '_'

rand

public static java.lang.String rand()
Generates a random number in String format
Returns:
a random string of digits

currTime

public static java.lang.String currTime()
Creates a string representing current time
Returns:
Time string, seconds since epoch start

secTime

public static java.lang.String secTime(java.util.Date date)
Creates a string representing time
Parameters:
date - Date value
Returns:
Time string, seconds since epoch start

string2array

public static java.lang.String[] string2array(java.lang.String v,
                                              java.lang.String d)
Splits a String at delimiters into a String[] array.
Parameters:
v - String. Example: "a,b,c" will be converted to String[] = {"a", "b", "c"} if d == ",".
d - String of delimiter characters