com.judoscript.util
Class Lib

java.lang.Object
  extended by com.judoscript.util.SimpleLib
      extended by com.judoscript.util.Lib

public class Lib
extends SimpleLib

This class is a giant collection of one-stop helper functions that can be used directly from applications. Using these functions eliminates the need of creating helper objects, setting options and getting the results. These functions are all static final, and mostly implemented with try-catch, so performance overhead is minimal.


Field Summary
static boolean debug
           
static java.util.Enumeration EMPTY_ENUM
           
static java.lang.String[] emptyStringArray
           
static java.lang.String indentText
           
static boolean is_windows
           
static boolean thread_safe
          Some functions, such as formatting and date manipulation, typically share some objects.
 
Method Summary
static java.lang.String __METHOD__(java.lang.String toExclude, boolean includeFileLine, java.lang.String msg, java.lang.String reference)
          Category: Debugging
static java.lang.String __METHOD__(java.lang.String toExclude, boolean includeFileLine, java.lang.String msg, java.lang.String reference, java.lang.Exception excpt)
           
static void appendChars(java.lang.StringBuffer sb, char filler, int len)
           
static java.lang.String array2String(java.lang.Object[] oa)
           
static byte[] base64Decode(char[] data)
           
static byte[] base64Decode(java.lang.String data)
           
static char[] base64Encode(byte[] data)
           
static java.lang.String capitalizeAllFirstLetters(java.lang.String s)
           
static java.lang.String capitalizeFirstLetter(java.lang.String s)
           
static java.lang.String centerAlign(java.lang.String val, int width)
           
static java.lang.String centerAlign(java.lang.String val, int width, boolean strict)
           
static java.lang.String centerAlign(java.lang.String val, int width, boolean strict, boolean isNum)
           
static java.lang.String centerAlign(java.lang.String val, int width, boolean strict, char filler, java.lang.String mark)
           
static java.lang.String cleanupPath(java.lang.String path)
           
static int compareToNullable(java.lang.Comparable obj1, java.lang.Comparable obj2)
           
static boolean copyFile(java.io.File src, java.io.File dest, boolean doCheck, StreamCopier sc)
           
static long copyStream(java.io.InputStream is, java.io.OutputStream os)
           
static long copyStream(java.io.InputStream is, java.io.OutputStream os, boolean close)
           
static int count(java.lang.String s, char c)
           
static int count(java.lang.String s, java.lang.String pat)
           
static int countFileLines(java.io.File f)
           
static int countFileWords(java.io.File f)
           
static int countWords(java.lang.String line)
           
static long createID()
           
static StringPrintWriter createStringPrintWriter()
           
static double decimalDigits(double val, int digits)
           
static java.lang.String decimalDigitsAsString(double val, int digits)
           
static long decodeNumber(java.lang.String s)
           
static TableData describeResultSet(java.sql.ResultSetMetaData rsmd)
           
static TableData describeTable(java.sql.Connection con, java.lang.String table)
           
static java.lang.String encodeNumber(long i)
           
static boolean endsWith(java.lang.StringBuffer sb, java.lang.String s)
           
static void ensureDirectory(java.io.File path)
           
static java.lang.String ensureLength(java.lang.String val, int len)
           
static java.lang.String ensureLength(java.lang.String val, int len, char filler)
           
static void ensurePath(java.io.File f)
           
static void ensureSize(java.util.List list, int size)
           
static boolean Equals(java.lang.Object obj1, java.lang.Object obj2)
          Category: General
static boolean equalsNullable(java.lang.Object obj1, java.lang.Object obj2)
          Category: General
static java.lang.String escapeNL(java.lang.String s)
           
static java.lang.String exactLength(java.lang.String val, int len)
           
static java.lang.String exactLength(java.lang.String val, int len, char filler)
           
static boolean existsProperty(java.lang.String name)
          Category: General
static java.lang.String formatDuration(int seconds)
          formats the seconds into days, hours, minutes and seconds.
static java.lang.String formTag(java.lang.String uri, java.lang.String local)
          For XML tag names with or without namespace.
static boolean getBoolProperty(java.lang.String name)
          Category: General
static boolean getBoolProperty(java.lang.String name, boolean defVal)
          Category: General
static java.lang.String getClassName(java.lang.Class e)
           
static java.lang.String getColumnTypeDisplayName(java.sql.ResultSetMetaData rsmd, int col)
           
static java.lang.String getCurrentDir()
           
static java.lang.String getEnvVar(java.lang.String name)
           
static java.util.Properties getEnvVars()
           
static java.lang.String getExceptionMsg(java.lang.String msg, java.lang.Throwable e)
          A convenience function that, when the exception has no message, just append a "." to the user message; otherwise, append ":" and the exception.
static java.lang.String getFileExt(java.lang.String path)
           
static java.lang.String getFileName(java.lang.String path)
           
static java.lang.String getFiller(int len, char filler)
           
static java.lang.Object getFirst(java.lang.Object[] oa)
           
static java.lang.String getHomeDir()
           
static java.lang.String getHostName()
           
static int getIntProperty(java.lang.String name)
          Category: General
static int getIntProperty(java.lang.String name, int defVal)
          Category: General
static java.lang.String[] getKeys(java.util.Map ht)
          Get all keys as String's sorted ascending
static java.lang.String[] getKeys(java.util.Map ht, java.util.Comparator cptr)
           
static java.lang.String getParentPath(java.lang.String path)
           
static java.lang.String getPath(java.lang.String path)
          Handles the leading '~' situation.
static java.lang.String getProperty(java.lang.String name)
          Category: General
static java.lang.String getProperty(java.lang.String name, java.lang.String defVal)
          Category: General
static java.lang.Class[] getPublicClasses(java.lang.Class c)
           
static java.lang.Class[] getPublicClasses(java.lang.Object o, java.lang.Class c)
           
static java.util.Comparator getSectionNumberComparator()
           
static int getSize(java.util.List list)
          Category: General
static int getSize(java.util.Map ht)
          Category: General
static java.lang.String getStackTrace(java.lang.Throwable t)
          Category: Debugging
static java.lang.Thread[] getThreads(java.lang.ThreadGroup tg)
           
static java.lang.String getUserName()
           
static java.lang.String groupNumber(long val)
           
static java.lang.String groupNumber(long val, int size, char separator)
           
static void gzip(java.lang.String fname, java.lang.String outFile, boolean compress)
           
static boolean hasResults(java.sql.ResultSet rs)
           
static void here()
          Category: Debugging
static void here(double d)
           
static void here(int i)
           
static void here(long i)
           
static void here(java.lang.Object o)
           
static void here(java.lang.String msg)
          Category: Debugging
static void hereWrt(java.lang.String reference)
           
static void hereWrt(java.lang.String msg, java.lang.String reference)
           
static int indexOf(java.lang.StringBuffer sb, java.lang.String s)
           
static int indexOfWhitespace(java.lang.String s)
           
static int indexOfWhitespace(java.lang.String s, int start)
           
static boolean isAbsolutePath(java.lang.String path)
           
static boolean isFileNewer(java.lang.Object one, java.lang.Object two)
           
static boolean isHPUX()
          Category: General
static boolean isLinux()
          Category: General
static boolean isMac()
          Category: General
static boolean isNetscape()
          Category: General
static boolean isOS400()
          Category: General
static boolean isServerSideException(java.lang.String stackTrace)
          Category: General
static boolean isServerSideException(java.lang.Throwable t)
          Category: General
static boolean isSunOS()
          Category: General
static boolean isSunVendor()
          Category: General
static boolean isUnix()
          Category: General
static boolean isWindows()
          Category: General
static java.lang.String javaVendor()
          Category: General
static void killAllThreads(java.lang.ThreadGroup tg)
           
static int lastIndexOf(java.lang.StringBuffer sb, java.lang.String s)
           
static int lastIndexOfWhitespace(java.lang.String s)
           
static int lastIndexOfWhitespace(java.lang.String s, int start)
           
static java.lang.String leftAlign(java.lang.String val, int width)
           
static java.lang.String leftAlign(java.lang.String val, int width, boolean strict)
           
static java.lang.String leftAlign(java.lang.String val, int width, boolean strict, boolean isNum)
           
static java.lang.String leftAlign(java.lang.String val, int width, boolean strict, char filler, java.lang.String mark)
           
static java.lang.String limitLength(java.lang.String val, int len)
           
static java.lang.String limitLength(java.lang.String val, int len, java.lang.String mark)
           
static java.lang.String[] linesToArray(java.lang.String s)
           
static void moveFile(java.io.File src, java.io.File dest)
           
static java.lang.Object newInstance(java.lang.Class cls, java.lang.Object param)
           
static java.lang.String osName()
          Category: General
static java.lang.String[] parseCmdline(java.lang.String cmdline)
          Parses the string as a Unix style command-line, supporting double-quote quoted values as-is.
static java.util.Map parseCmdline(java.lang.String[] args)
          The supported command line format:
static java.lang.String[] parseFixedPosition(java.lang.String s, int[] lens)
           
static java.util.HashMap parseUrl(java.lang.String url, java.lang.String base)
           
static boolean pathStartsWith(java.lang.String path, java.lang.String base)
           
static java.lang.String removeDotsInPath(java.lang.String path)
           
static void rest(java.lang.Object o)
          Category: General
static java.lang.String rightAlign(java.lang.String val, int width)
           
static java.lang.String rightAlign(java.lang.String val, int width, boolean strict)
           
static java.lang.String rightAlign(java.lang.String val, int width, boolean strict, boolean isNum)
           
static java.lang.String rightAlign(java.lang.String val, int width, boolean strict, char filler, java.lang.String mark)
           
static java.lang.ThreadGroup rootThreadGroup()
           
static java.lang.String sectionNumberToName(java.lang.String sect)
           
static void showCallStack()
           
static boolean sleep(long millis)
          Category: General
static boolean sleep(java.lang.Object o, long millis)
          Category: General
static boolean startsWith(java.lang.StringBuffer sb, java.lang.String s)
           
static java.lang.String[] string2Array(java.lang.String s, int delim, boolean trim)
          The input string s is parsed into a string array; it behaves differently from java.util.StringTokenizer in that, consecutive delimiters in the input string are not considered as a single delimiter but rather return empty strings ("") for them.
static java.lang.String[] string2Array(java.lang.String s, int delim, boolean trim, int minLen, java.lang.String defaultString)
          The input string s is parsed into a string array; it behaves differently from java.util.StringTokenizer in that, consecutive delimiters in the input string are not considered as a single delimiter but rather return empty strings ("") for them.
static java.util.List stringTemplate(java.lang.String s, java.lang.String leftDelim, java.lang.String rightDelim)
          Parses the string for embedded tags.
static long sum(int[] ia)
           
static void throwFileNotFoundException(java.lang.String filename)
           
static java.lang.String toAbsoluteUrl(java.lang.String url, java.lang.String base)
           
static java.lang.String toFixedPosition(java.lang.Object[] oa, int[] ia)
           
static java.lang.String[] tokenize(java.lang.String s, java.lang.String delims)
          Behaves in the same way as java.util.StringTokenizer except it returns a String[].
static java.lang.String toOSPath(java.lang.String path)
           
static java.net.URL toURL(java.lang.String s)
          If s represents a file that exists, a file URL will be returned.
static java.lang.String trim(java.lang.String s, char decorator)
           
static java.lang.String trim(java.lang.String s, java.lang.String decorator)
           
static java.lang.String unit(long cnt, java.lang.String singular, java.lang.String plural)
           
static void wait(long starttime, long dur, boolean interruptable)
          Category: General
 
Methods inherited from class com.judoscript.util.SimpleLib
equals, existsClass, hex, leadToUpperCase, neverNull, parseInt, parseInt, parseLong, parseLongHex, replace, startsWith, toStringArray, toStringNeverNull, toStringNeverNull, unquote, unquote, unquote
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ENUM

public static java.util.Enumeration EMPTY_ENUM

debug

public static boolean debug

thread_safe

public static boolean thread_safe
Some functions, such as formatting and date manipulation, typically share some objects. If thread_safe is true, these functions are synchronized.

In a single-threaded program, you can turn this off to gain some performance boost.


indentText

public static java.lang.String indentText

emptyStringArray

public static final java.lang.String[] emptyStringArray

is_windows

public static final boolean is_windows
Method Detail

getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable t)
Category: Debugging


showCallStack

public static void showCallStack()

__METHOD__

public static java.lang.String __METHOD__(java.lang.String toExclude,
                                          boolean includeFileLine,
                                          java.lang.String msg,
                                          java.lang.String reference)
Category: Debugging

This method serves the same purposes as the C built-in macros __FILE__ and __LINE__. It returns the current method location from which it is called.

toExclude is optionally a method name to be ignored.

A typical use is to create your own debug method like this:

public class MyClass
{
  static final boolean debugging = true;

  static final void dbg(String msg) {
    if (debugging)
      System.out.println("### " + __METHOD__("dbg",true,null,null) + msg);
  }

  public void foo(String bar) {
    dbg(bar);
    .....
  }
}
When foo("abcde") is called, it will print out a message on System.out:
  ### (MyClass.java:34) foo(): abcde

Parameters:
toExclude - if not null, the latest lines containing this string is ignored.
reference - if not null, the distance from the found line and a previous line that contains this pattern is used as a call depth and the resultant text is accordingly indented.
Returns:
current_method(): msg if includeFileLine is false, or (file_name:line_num) current_method(): msg
if includeFileLine is true. If pattern is not null, it is indented.
Note that if the class is compiled without debug information, or JIT is on at run-time, the line number may not be available.

__METHOD__

public static java.lang.String __METHOD__(java.lang.String toExclude,
                                          boolean includeFileLine,
                                          java.lang.String msg,
                                          java.lang.String reference,
                                          java.lang.Exception excpt)

here

public static void here()
Category: Debugging

A quick debugging method that prints out the current file and method name on to System.out.

See Also:
__METHOD__(java.lang.String,boolean,java.lang.String,java.lang.String)

here

public static void here(int i)

here

public static void here(long i)

here

public static void here(double d)

here

public static void here(java.lang.Object o)

here

public static void here(java.lang.String msg)
Category: Debugging

A quick debugging method that prints out the current file and method name on to System.out.

See Also:
__METHOD__(java.lang.String,boolean,java.lang.String)

hereWrt

public static void hereWrt(java.lang.String reference)

hereWrt

public static void hereWrt(java.lang.String msg,
                           java.lang.String reference)

Equals

public static boolean Equals(java.lang.Object obj1,
                             java.lang.Object obj2)
Category: General

Returns:
true if these two objects are both not null and equals() returns true

equalsNullable

public static boolean equalsNullable(java.lang.Object obj1,
                                     java.lang.Object obj2)
Category: General

Returns:
true if these two objects are either both null or equals() returns true

compareToNullable

public static int compareToNullable(java.lang.Comparable obj1,
                                    java.lang.Comparable obj2)

sleep

public static boolean sleep(long millis)
Category: General

Have the current thread to sleep for milliseconds.

Returns:
true if the period is completed; false if interrupted.

rest

public static void rest(java.lang.Object o)
Category: General

Calls o's wait() and rest until the object is awaken or interrupted.


sleep

public static boolean sleep(java.lang.Object o,
                            long millis)
Category: General

Calls o's wait() and rest until the object is awaken or interrupted.

Returns:
true if the period is completed; false if interrupted.

wait

public static void wait(long starttime,
                        long dur,
                        boolean interruptable)
Category: General

Waits dur milliseconds on object o since the starttime.

If interruptable is false, when interrupted, it goes back to sleep until the duration of rest has elapsed. Otherwise, it returns immediately.


getSize

public static int getSize(java.util.List list)
Category: General

Returns:
the size of the List, or 0 if null

ensureSize

public static void ensureSize(java.util.List list,
                              int size)

getSize

public static int getSize(java.util.Map ht)
Category: General

Returns:
the size of the Map, or 0 if null

existsProperty

public static boolean existsProperty(java.lang.String name)
Category: General


getProperty

public static java.lang.String getProperty(java.lang.String name)
Category: General


getProperty

public static java.lang.String getProperty(java.lang.String name,
                                           java.lang.String defVal)
Category: General


getIntProperty

public static int getIntProperty(java.lang.String name)
Category: General


getIntProperty

public static int getIntProperty(java.lang.String name,
                                 int defVal)
Category: General


getBoolProperty

public static boolean getBoolProperty(java.lang.String name)
Category: General


getBoolProperty

public static boolean getBoolProperty(java.lang.String name,
                                      boolean defVal)
Category: General


isServerSideException

public static boolean isServerSideException(java.lang.String stackTrace)
Category: General

Useful for EJB clients to check if an exception is a server-side one or not.


isServerSideException

public static boolean isServerSideException(java.lang.Throwable t)
Category: General

Useful for EJB clients to check if an exception is a server-side one or not.


getExceptionMsg

public static java.lang.String getExceptionMsg(java.lang.String msg,
                                               java.lang.Throwable e)
A convenience function that, when the exception has no message, just append a "." to the user message; otherwise, append ":" and the exception.


throwFileNotFoundException

public static void throwFileNotFoundException(java.lang.String filename)
                                       throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

isMac

public static boolean isMac()
Category: General


isWindows

public static boolean isWindows()
Category: General


isUnix

public static boolean isUnix()
Category: General


isOS400

public static boolean isOS400()
Category: General


isHPUX

public static boolean isHPUX()
Category: General


isLinux

public static boolean isLinux()
Category: General


isSunOS

public static boolean isSunOS()
Category: General


osName

public static java.lang.String osName()
Category: General


javaVendor

public static java.lang.String javaVendor()
Category: General


isNetscape

public static boolean isNetscape()
Category: General


isSunVendor

public static boolean isSunVendor()
Category: General


tokenize

public static java.lang.String[] tokenize(java.lang.String s,
                                          java.lang.String delims)
Behaves in the same way as java.util.StringTokenizer except it returns a String[].


count

public static int count(java.lang.String s,
                        char c)
Returns:
the number of apperances of c in s.

count

public static int count(java.lang.String s,
                        java.lang.String pat)

string2Array

public static java.lang.String[] string2Array(java.lang.String s,
                                              int delim,
                                              boolean trim,
                                              int minLen,
                                              java.lang.String defaultString)
The input string s is parsed into a string array; it behaves differently from java.util.StringTokenizer in that, consecutive delimiters in the input string are not considered as a single delimiter but rather return empty strings ("") for them.

Parameters:
delim - the delimiter character
trim - if true, trim the result strings
minLen - the returned String[] has at least this many cells
defaultString - in case the number of available strings are less then minLen, the empty cells will be filled with this value

array2String

public static java.lang.String array2String(java.lang.Object[] oa)

string2Array

public static java.lang.String[] string2Array(java.lang.String s,
                                              int delim,
                                              boolean trim)
The input string s is parsed into a string array; it behaves differently from java.util.StringTokenizer in that, consecutive delimiters in the input string are not considered as a single delimiter but rather return empty strings ("") for them.

Parameters:
delim - the delimiter character
trim - if true, trim the result strings

parseCmdline

public static java.lang.String[] parseCmdline(java.lang.String cmdline)
Parses the string as a Unix style command-line, supporting double-quote quoted values as-is.


isAbsolutePath

public static boolean isAbsolutePath(java.lang.String path)

cleanupPath

public static java.lang.String cleanupPath(java.lang.String path)

pathStartsWith

public static boolean pathStartsWith(java.lang.String path,
                                     java.lang.String base)

formatDuration

public static java.lang.String formatDuration(int seconds)
formats the seconds into days, hours, minutes and seconds.


getFiller

public static java.lang.String getFiller(int len,
                                         char filler)

appendChars

public static void appendChars(java.lang.StringBuffer sb,
                               char filler,
                               int len)

centerAlign

public static java.lang.String centerAlign(java.lang.String val,
                                           int width,
                                           boolean strict,
                                           char filler,
                                           java.lang.String mark)
Returns:
a string that is center aligned to width, if the string length does not exceed width. When this happens, it will be led and trailed by filler. If strict is true and val is longer than width, the string will be chopped from both ends to fit.

centerAlign

public static java.lang.String centerAlign(java.lang.String val,
                                           int width,
                                           boolean strict)

centerAlign

public static java.lang.String centerAlign(java.lang.String val,
                                           int width)

centerAlign

public static java.lang.String centerAlign(java.lang.String val,
                                           int width,
                                           boolean strict,
                                           boolean isNum)

leftAlign

public static java.lang.String leftAlign(java.lang.String val,
                                         int width,
                                         boolean strict,
                                         char filler,
                                         java.lang.String mark)

leftAlign

public static java.lang.String leftAlign(java.lang.String val,
                                         int width,
                                         boolean strict)

leftAlign

public static java.lang.String leftAlign(java.lang.String val,
                                         int width)

leftAlign

public static java.lang.String leftAlign(java.lang.String val,
                                         int width,
                                         boolean strict,
                                         boolean isNum)

rightAlign

public static java.lang.String rightAlign(java.lang.String val,
                                          int width,
                                          boolean strict,
                                          char filler,
                                          java.lang.String mark)

rightAlign

public static java.lang.String rightAlign(java.lang.String val,
                                          int width,
                                          boolean strict)

rightAlign

public static java.lang.String rightAlign(java.lang.String val,
                                          int width)

rightAlign

public static java.lang.String rightAlign(java.lang.String val,
                                          int width,
                                          boolean strict,
                                          boolean isNum)

ensureLength

public static java.lang.String ensureLength(java.lang.String val,
                                            int len)
Returns:
a string ensured to be of at least length len. If the string is short than expected, spaces are filled to the tail (if len is positive) or head (if len is negative).

ensureLength

public static java.lang.String ensureLength(java.lang.String val,
                                            int len,
                                            char filler)
Returns:
a string ensured to be of at least length len. If the string is short than expected, the filler are filled to the tail (if len is positive) or head (if len is negative).

exactLength

public static java.lang.String exactLength(java.lang.String val,
                                           int len)
Returns:
a string guaranteed to be of length len. If the string is longer, it will be chopped off from the tail (if len is positive) of from the head (if len is nagive). If the string is short than expected, spaces are filled to ensure the length.

exactLength

public static java.lang.String exactLength(java.lang.String val,
                                           int len,
                                           char filler)
Returns:
a string guaranteed to be of length len. If the string is longer, it will be chopped off from the tail (if len is positive) of from the head (if len is nagive). If the string is short than expected, the filler are filled to ensure the length.

limitLength

public static java.lang.String limitLength(java.lang.String val,
                                           int len)
Parameters:
val - the value string
len - the intended length. If positive, limits the length from the head; if negative, from tail.
Returns:
a string that is no longer than the specified length; if the string is longer than the specified length, the string will be chopped off from the tail (if len is positive) or from the head (if len is negative).

limitLength

public static java.lang.String limitLength(java.lang.String val,
                                           int len,
                                           java.lang.String mark)
Parameters:
val - the value string
len - the intended length. If positive, limits the length from the head; if negative, from tail.
mark - if not null, is appended (if len is positive) or prepended (if len is negative) to the tail or head of the cut-off string.
Returns:
a string that is no longer than the specified length; if the string is longer than the specified length, the string will be chopped off from the tail (if len is positive) or from the head (if len is negative). if mark is not null, it will be appended or prepended to the result. The resultant length never exceeds that specified.

parseCmdline

public static java.util.Map parseCmdline(java.lang.String[] args)
The supported command line format:
  java java_class_name ( /name[=value] | -name[=value] | param )* 

Returns:
a hashtable for all the options; if value part is missing, defaulted to 'true'. special entry "-args" is an array of ( param )*, if any.

formTag

public static java.lang.String formTag(java.lang.String uri,
                                       java.lang.String local)
For XML tag names with or without namespace.


getKeys

public static java.lang.String[] getKeys(java.util.Map ht)
Get all keys as String's sorted ascending


getKeys

public static java.lang.String[] getKeys(java.util.Map ht,
                                         java.util.Comparator cptr)

sectionNumberToName

public static java.lang.String sectionNumberToName(java.lang.String sect)

getSectionNumberComparator

public static java.util.Comparator getSectionNumberComparator()

copyStream

public static long copyStream(java.io.InputStream is,
                              java.io.OutputStream os)
                       throws java.io.IOException
Throws:
java.io.IOException

copyStream

public static long copyStream(java.io.InputStream is,
                              java.io.OutputStream os,
                              boolean close)
                       throws java.io.IOException
Throws:
java.io.IOException

copyFile

public static boolean copyFile(java.io.File src,
                               java.io.File dest,
                               boolean doCheck,
                               StreamCopier sc)
                        throws java.io.IOException
Throws:
java.io.IOException

moveFile

public static void moveFile(java.io.File src,
                            java.io.File dest)
                     throws java.io.IOException
Throws:
java.io.IOException

getFileName

public static java.lang.String getFileName(java.lang.String path)

getParentPath

public static java.lang.String getParentPath(java.lang.String path)

getFileExt

public static java.lang.String getFileExt(java.lang.String path)

getHomeDir

public static java.lang.String getHomeDir()

getCurrentDir

public static java.lang.String getCurrentDir()

getUserName

public static java.lang.String getUserName()

groupNumber

public static java.lang.String groupNumber(long val)

groupNumber

public static java.lang.String groupNumber(long val,
                                           int size,
                                           char separator)

decimalDigitsAsString

public static java.lang.String decimalDigitsAsString(double val,
                                                     int digits)

decimalDigits

public static double decimalDigits(double val,
                                   int digits)

sum

public static long sum(int[] ia)

getClassName

public static java.lang.String getClassName(java.lang.Class e)

indexOfWhitespace

public static int indexOfWhitespace(java.lang.String s)

indexOfWhitespace

public static int indexOfWhitespace(java.lang.String s,
                                    int start)

lastIndexOfWhitespace

public static int lastIndexOfWhitespace(java.lang.String s)

lastIndexOfWhitespace

public static int lastIndexOfWhitespace(java.lang.String s,
                                        int start)

removeDotsInPath

public static java.lang.String removeDotsInPath(java.lang.String path)

ensureDirectory

public static void ensureDirectory(java.io.File path)
                            throws java.io.IOException
Throws:
java.io.IOException

createID

public static long createID()

encodeNumber

public static java.lang.String encodeNumber(long i)

decodeNumber

public static long decodeNumber(java.lang.String s)
                         throws java.lang.NumberFormatException
Throws:
java.lang.NumberFormatException

toAbsoluteUrl

public static java.lang.String toAbsoluteUrl(java.lang.String url,
                                             java.lang.String base)

parseUrl

public static java.util.HashMap parseUrl(java.lang.String url,
                                         java.lang.String base)
Returns:
a Map of these keys:
  • url: the URL; if base is present, it's the resolved URL.
  • protocol
  • domain
  • root
  • host
  • path: the firtual path of the URL.
  • ref
  • query_string
  • file_name

getColumnTypeDisplayName

public static java.lang.String getColumnTypeDisplayName(java.sql.ResultSetMetaData rsmd,
                                                        int col)
                                                 throws java.lang.Exception
Throws:
java.lang.Exception

newInstance

public static java.lang.Object newInstance(java.lang.Class cls,
                                           java.lang.Object param)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

base64Encode

public static char[] base64Encode(byte[] data)

base64Decode

public static byte[] base64Decode(java.lang.String data)

base64Decode

public static byte[] base64Decode(char[] data)

hasResults

public static boolean hasResults(java.sql.ResultSet rs)

describeResultSet

public static TableData describeResultSet(java.sql.ResultSetMetaData rsmd)
                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

describeTable

public static TableData describeTable(java.sql.Connection con,
                                      java.lang.String table)
                               throws java.sql.SQLException
Throws:
java.sql.SQLException

unit

public static java.lang.String unit(long cnt,
                                    java.lang.String singular,
                                    java.lang.String plural)

rootThreadGroup

public static java.lang.ThreadGroup rootThreadGroup()

getThreads

public static java.lang.Thread[] getThreads(java.lang.ThreadGroup tg)

killAllThreads

public static void killAllThreads(java.lang.ThreadGroup tg)

getFirst

public static java.lang.Object getFirst(java.lang.Object[] oa)

getPublicClasses

public static java.lang.Class[] getPublicClasses(java.lang.Object o,
                                                 java.lang.Class c)

getPublicClasses

public static java.lang.Class[] getPublicClasses(java.lang.Class c)

ensurePath

public static void ensurePath(java.io.File f)

isFileNewer

public static boolean isFileNewer(java.lang.Object one,
                                  java.lang.Object two)

getPath

public static java.lang.String getPath(java.lang.String path)
Handles the leading '~' situation.


getEnvVars

public static java.util.Properties getEnvVars()

getEnvVar

public static java.lang.String getEnvVar(java.lang.String name)

gzip

public static void gzip(java.lang.String fname,
                        java.lang.String outFile,
                        boolean compress)
                 throws java.io.IOException
Throws:
java.io.IOException

endsWith

public static boolean endsWith(java.lang.StringBuffer sb,
                               java.lang.String s)

startsWith

public static boolean startsWith(java.lang.StringBuffer sb,
                                 java.lang.String s)

indexOf

public static int indexOf(java.lang.StringBuffer sb,
                          java.lang.String s)

lastIndexOf

public static int lastIndexOf(java.lang.StringBuffer sb,
                              java.lang.String s)

capitalizeFirstLetter

public static java.lang.String capitalizeFirstLetter(java.lang.String s)

capitalizeAllFirstLetters

public static java.lang.String capitalizeAllFirstLetters(java.lang.String s)

countFileLines

public static int countFileLines(java.io.File f)
                          throws java.io.IOException
Throws:
java.io.IOException

countFileWords

public static int countFileWords(java.io.File f)
                          throws java.io.IOException
Throws:
java.io.IOException

countWords

public static int countWords(java.lang.String line)

escapeNL

public static java.lang.String escapeNL(java.lang.String s)

parseFixedPosition

public static java.lang.String[] parseFixedPosition(java.lang.String s,
                                                    int[] lens)

toFixedPosition

public static java.lang.String toFixedPosition(java.lang.Object[] oa,
                                               int[] ia)

toOSPath

public static java.lang.String toOSPath(java.lang.String path)

getHostName

public static java.lang.String getHostName()

trim

public static java.lang.String trim(java.lang.String s,
                                    char decorator)

trim

public static java.lang.String trim(java.lang.String s,
                                    java.lang.String decorator)

createStringPrintWriter

public static StringPrintWriter createStringPrintWriter()

stringTemplate

public static java.util.List stringTemplate(java.lang.String s,
                                            java.lang.String leftDelim,
                                            java.lang.String rightDelim)
Parses the string for embedded tags. Tags starts with leftDelim and ends with rightDelim.

Returns:
If no tags present, null is returned. Otherwise, a List of text/tags is returned, with elements 0, 2, 4, ... being text and 1, 3, 5, ... being tags; text elements can be "".

linesToArray

public static java.lang.String[] linesToArray(java.lang.String s)

toURL

public static java.net.URL toURL(java.lang.String s)
                          throws java.net.MalformedURLException
If s represents a file that exists, a file URL will be returned. Otherwise, simply new URL(s).

Throws:
java.net.MalformedURLException