to.etc.util
Class StringTool

java.lang.Object
  extended by to.etc.util.StringTool

public class StringTool
extends java.lang.Object

This static utility class contains a load of string functions. And some other stuff I could not quickly find a place for ;-)

Version:
1.0
Author:
Frits Jalvingh

Constructor Summary
StringTool()
           
 
Method Summary
static void addPathToVector(java.util.List<java.lang.String> v, java.lang.String p)
          Adds a path to the vector specified, if the path is an existing file or directory, and it doesn't already exist in the vector.
static void addSearchEnvToVector(java.util.List<java.lang.String> v, java.lang.String envvar)
          Adds the value of a "search path environment variable" to the vector.
static void addSearchPathToVector(java.util.List<java.lang.String> v, java.lang.String searchpath)
          Takes a search path, i.e.
static void arrayToAsciiStr(java.lang.Appendable sb, byte[] ar, int bi, int nc)
          Returns a string containing only printable chars for the given bytes.
static void arrayToDumpLine(java.lang.Appendable sb, byte[] ar, int bi, int nc)
          Returns a dumpstring containing the offset, the hex bytes, and the ascii representation of a given dump buffer.
static void arrayToHexStr(java.lang.Appendable sb, byte[] ar, int bi, int nc, boolean fillout)
          Returns a string of hex bytes for a given thing.
static void createInsertStatement(java.lang.StringBuilder sb, java.lang.String table, java.lang.String pkname, java.lang.String pkexpr, java.lang.String[] fields)
           
static void createUpdateStatement(java.lang.StringBuilder sb, java.lang.String table, java.lang.String pkname, java.lang.String[] fields)
           
static boolean dbGetBool(java.lang.String fv)
          Returns a boolean value from some database field.
static java.lang.String dbSetBool(boolean v)
          Returns a char(1) value to store in a database for booleans.
static byte[] decodeBase64(byte[] data)
          This method decodes the given byte[] using the base64-encoding specified in RFC-2045 (Section 6.8).
static byte[] decodeBase64(java.lang.String str)
          This method decodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8).
static java.lang.String decodeBase64ToString(java.lang.String str)
          This method decodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8).
static java.lang.String decodeURLEncoded(java.lang.String encoded)
          Decode the URLEncoded string passed to a real string.
static void dumpData(java.lang.Appendable sb, byte[] ar, int off, int len)
          Dump the data as a formatted multiline buffer: like
static void dumpLocation(java.lang.String msg)
           
static byte[] encodeBase64(byte[] data)
          This method encodes the given byte[] using the base64-encoding specified in RFC-2045 (Section 6.8).
static java.lang.String encodeBase64(java.lang.String str)
          This method encodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8).
static java.lang.String encodeBase64ToString(byte[] data)
           
static void encodeURLEncoded(java.lang.Appendable sb, java.lang.String str)
          Encode the string passed to URLEncoded format.
static java.lang.String encodeURLEncoded(java.lang.String str)
           
static void entitiesToUnicode(java.lang.Appendable sb, java.lang.String str, boolean ignoremarkers)
          Scans the input string for entities and replaces all entities that are actually found with their Unicode character code.
static int entityToUnicode(java.lang.String ename)
          Translates an entity name to unicode.
static boolean equalStringList(java.util.List<java.lang.String> inl, java.util.List<java.lang.String> al, boolean caseindependent)
           
static java.lang.String extractSingleLine(java.lang.String in)
          Tries to extract a single line of max.
static java.io.File findFileOnEnv(java.lang.String pname, java.lang.String env)
          Finds a filename along the classpath..
static java.io.File findFileOnPath(java.lang.String fname, java.lang.String path)
          Returns the complete filename of the first file that is found along the path specified.
static java.lang.String fixFileURL(java.lang.String fileurl)
           
static byte[] fromHex(java.lang.String s)
          Decodes a hex string into a byte array.
static java.lang.String generateGUID()
          Generate an unique identifier with reasonable expectations that it will be globally unique.
static byte[] getBase64Map()
           
static java.util.List<java.lang.String> getEnvironment()
          Returns the list of environment variables of the supported OS's.
static java.lang.String getExceptionMessage(java.lang.Throwable t)
          If the throwable passed as a message then return it verbatim, else return the exception's classname.
static java.lang.String getFileExtension(java.lang.String fn)
          Deprecated.  
static java.lang.String getFinalFrom(java.lang.Class<?> cl, long sval)
           
static java.lang.String getFinalFrom(java.lang.Class<?> cl, long sval, java.lang.String part)
          Traverses a given class and tries to find a public
static java.lang.String getFinalFrom(java.lang.Class<?> cl, long sval, java.lang.String part, java.lang.String ign)
          Traverses a given class and tries to find a public
static int getJreVersion()
           
static int getLevenshteinDistance(java.lang.String s, java.lang.String t, boolean ignorecase)
          This returns the Levenshtein distance between two strings, which is the number of changes (adds, removes) that are needed to convert source into target.
static java.lang.String getLocation()
           
static void getLocation(java.lang.StringBuffer sb)
           
static java.lang.String getNextPathComponent(int ix, java.lang.String s, boolean includeslash)
          Find the 1st part of the path passed, i.e.
static java.lang.String getNextPathComponent(java.lang.String s, boolean includeslash)
           
static void htmlStringize(java.lang.Appendable o, java.lang.String is)
          Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent.
static java.lang.String htmlStringize(java.lang.String is)
          Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent.
static void htmlStringize(java.lang.StringBuilder sb, java.lang.String is)
          Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent.
static java.lang.String intToStr(int val, int radix, int npos)
          Returns a number in the specified base, and with the specified #of positions.
static boolean isAllSpaces(java.lang.String s)
           
static boolean isDomainChar(char c)
           
static boolean isEqual(java.lang.Object a, java.lang.Object b)
           
static boolean isNumber(java.lang.String s)
           
static boolean isValidDbFieldName(java.lang.String s)
          Field name must start with ascii letter, then letters, digits or _.
static boolean isValidDomainName(java.lang.String s)
          Checks if the name is a valid domain name.
static boolean isValidDottedName(java.lang.String s)
           
static boolean isValidEmail(java.lang.String em)
           
static boolean isValidJavaIdentifier(java.lang.String s)
           
static boolean isWhiteSpaceOrNbsp(char c)
           
static void main(java.lang.String[] args)
           
static java.lang.String makeSearchPath(java.util.List<java.lang.String> v)
          Returns a string buffer containing a search path variable from the vector passed.
static java.lang.String makeSearchPath(java.lang.String[] v)
          Returns a string buffer containing a search path variable from the vector passed.
static void makeSearchPath(java.lang.StringBuffer sb, java.lang.String[] v)
          Returns a string buffer containing a search path variable from the vector passed.
static void makeSearchPath(java.lang.StringBuilder sb, java.util.List<java.lang.String> v)
          Returns a string buffer containing a search path variable from the vector passed.
static java.lang.String makeURL(java.io.File f)
          Workaround for Java bug delivering file:// instead of file:/// for file.toURL().toString().
static java.lang.String normalizeConcat(java.lang.String current, java.lang.String tpl)
          Called when generate() is called with a string.
static java.lang.String normalizeUndot(java.lang.String ins)
          Takes an input URL and handles all '.' and '..' replacements.
static java.lang.String normalizeURL(java.lang.String current, java.lang.String tpl)
          Called when generate() is called with a string.
static void parseString(java.lang.StringBuffer sb, java.lang.String s)
          Takes a java string, without quotes, and replaces all escape sequences in there with their actual character representation.
static void printHex(java.io.PrintStream pw, byte[] arr)
           
static void printHex(java.io.PrintStream pw, byte[] arr, int start, int end)
           
static void printHex(java.io.PrintWriter pw, byte[] arr)
           
static void printHex(java.io.PrintWriter pw, byte[] arr, int start, int end)
           
static java.lang.String removeRepeatingCharacters(java.lang.String in)
          Replaces long character sequences without space like ---- and ===== with a way shorter version.
static void strAddIntFixed(java.lang.Appendable sb, int val, int radix, int len)
          Converts the integer to a string with a fixed length, adding leading zeroes if needed.
static java.lang.String strBackslashToSlash(java.lang.String s)
          Takes an input string and replaces all occurences of the backslash with a forward slash.
static java.lang.String strCommad(long val)
          Returns a properly formatted commad string for a number [english only].
static java.lang.String strDuration(long dlt)
           
static java.lang.String strDurationMillis(long dlt)
           
static boolean strEndsWithIgnoreCase(java.lang.String st, java.lang.String with)
          Returns T if the string ends with the specified string, while ignoring case.
static int strIndexOfIgnoreCase(java.lang.String txt, java.lang.String match)
          Tries to locate a substring in a string while ignoring case.
static java.lang.StringBuffer stringize(java.lang.String s)
          Converts a string into a java-compilable version of a string, i.e.
static void stringize(java.lang.StringBuffer sb, java.lang.String s)
           
static java.lang.StringBuffer stringizeNQ(java.lang.String s)
           
static java.lang.String strNanoTime(long ns)
          Return a nanotime timestamp with 2 thousands of precision max.
static java.lang.String strOracleTruncate(java.lang.String in, int nchars)
          Handles Oracle truncation rules: If the string is > nchars truncate to nchars Convert the string to bytes in UTF-8 encoding If the string length, in bytes, is > 4000 bytes (the max stupid size of Oracle's stupid varchar2 column, stupid) remove characters until the string fits the stupidly limited Oracle column
static java.lang.String strReplace(java.lang.String src, java.lang.String old, java.lang.String nw)
          Case-sensitive replace of all occurences of [old] with [new].
static java.lang.String strSize(long sz)
          Returns a string representing some size, in bytes.
static void strStacktrace(java.lang.Appendable sb, java.lang.Throwable t)
           
static java.lang.String strStacktrace(java.lang.Throwable t)
           
static void strStacktraceFiltered(java.lang.Appendable sb, java.lang.Throwable t, java.lang.String[] skipbefore, java.lang.String[] skipafter, int linelimit)
          Report a filtered location stack trace, where the start of the stack trace and the end can be removed.
static boolean strStartsWithIgnoreCase(java.lang.String st, java.lang.String with)
          Returns T if the string starts with the specified string, while ignoring case.
static java.lang.String strToFixedLength(java.lang.String s, char c, int l)
          Returns a string with the specified length.
static java.lang.String strToFixedLength(java.lang.String s, int l)
          Returns a string with the specified length.
static int strToInt(java.lang.String v, int defval)
           
static void strToJavascriptString(java.lang.Appendable w, java.lang.String cs, boolean dblquote)
           
static java.lang.String strToJavascriptString(java.lang.String cs, boolean dblquote)
           
static long strToLong(java.lang.String v, int six, int eix, int defval)
           
static long strToLong(java.lang.String v, long defval)
           
static java.lang.String strTrunc(java.lang.String s, int len)
           
static java.lang.String strUnquote(java.lang.String s)
           
static java.lang.String strUnspace(java.lang.String s)
          Removes all whitespace from a string.
static java.lang.String toHex(byte[] arr)
          Converts the byte array to a hex string.
static java.lang.String toHex(byte[] arr, int start, int end)
          Converts the byte array passed to a hex string.
static java.lang.String toHexSp(byte[] arr)
          Converts the byte array to a hex string.
static java.lang.String toHexSp(byte[] arr, int start, int end)
          Converts the byte array passed to a hex string.
static java.lang.String toXY(int x, int y)
          Returns a coordinate pair as a string.
static java.lang.String truncLength(java.lang.String s, int maxlen)
          If the input string is too long, returns a substring containing at most maxlen characters.
static void unicodeToEntities(java.lang.StringBuffer sb, java.lang.String str)
          Replaces all non-ascii stuff with their entities.
static java.lang.String urlLastPart(java.lang.String url)
          Returns the last element (document name?) from the url passed.
static java.lang.String xmlStringize(java.lang.String is)
          Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent.
static void xmlStringize(java.lang.StringBuffer sb, java.lang.String is)
          Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTool

public StringTool()
Method Detail

isValidJavaIdentifier

public static boolean isValidJavaIdentifier(java.lang.String s)

isValidDomainName

public static boolean isValidDomainName(java.lang.String s)
Checks if the name is a valid domain name. These can contain only letters (a..z), digits (0..9), the dash and dots. Dots cannot start or end a name, nor can two dots occurs immediately next to another.

Parameters:
s -
Returns:

isNumber

public static boolean isNumber(java.lang.String s)

isDomainChar

public static boolean isDomainChar(char c)

isWhiteSpaceOrNbsp

public static boolean isWhiteSpaceOrNbsp(char c)

isAllSpaces

public static boolean isAllSpaces(java.lang.String s)

isValidEmail

public static boolean isValidEmail(java.lang.String em)

isValidDbFieldName

public static boolean isValidDbFieldName(java.lang.String s)
Field name must start with ascii letter, then letters, digits or _.

Parameters:
s -
Returns:

isValidDottedName

public static boolean isValidDottedName(java.lang.String s)

isEqual

public static boolean isEqual(java.lang.Object a,
                              java.lang.Object b)

stringize

public static void stringize(java.lang.StringBuffer sb,
                             java.lang.String s)

stringize

public static java.lang.StringBuffer stringize(java.lang.String s)
Converts a string into a java-compilable version of a string, i.e. surrounded by quotes, and with escape sequences escaped..


stringizeNQ

public static java.lang.StringBuffer stringizeNQ(java.lang.String s)

strBackslashToSlash

public static java.lang.String strBackslashToSlash(java.lang.String s)
Takes an input string and replaces all occurences of the backslash with a forward slash.


strSize

public static java.lang.String strSize(long sz)
Returns a string representing some size, in bytes. Depending on the size it will be represented as KB, MB, GB or TB.


parseString

public static void parseString(java.lang.StringBuffer sb,
                               java.lang.String s)
Takes a java string, without quotes, and replaces all escape sequences in there with their actual character representation.


truncLength

public static java.lang.String truncLength(java.lang.String s,
                                           int maxlen)
If the input string is too long, returns a substring containing at most maxlen characters.


strToFixedLength

public static java.lang.String strToFixedLength(java.lang.String s,
                                                int l)
Returns a string with the specified length. If the string is too long it is truncated; if it is too short it is filled with spaces.


strToFixedLength

public static java.lang.String strToFixedLength(java.lang.String s,
                                                char c,
                                                int l)
Returns a string with the specified length. If the string is too long it is truncated; if it is too short it is filled with c.


toXY

public static java.lang.String toXY(int x,
                                    int y)
Returns a coordinate pair as a string.


getLevenshteinDistance

public static int getLevenshteinDistance(java.lang.String s,
                                         java.lang.String t,
                                         boolean ignorecase)
This returns the Levenshtein distance between two strings, which is the number of changes (adds, removes) that are needed to convert source into target. The number of changes is an indication of the difference between those strings.


strStartsWithIgnoreCase

public static boolean strStartsWithIgnoreCase(java.lang.String st,
                                              java.lang.String with)
Returns T if the string starts with the specified string, while ignoring case.

Parameters:
st - the string whose start is to be checked
with - the start string
Returns:

strEndsWithIgnoreCase

public static boolean strEndsWithIgnoreCase(java.lang.String st,
                                            java.lang.String with)
Returns T if the string ends with the specified string, while ignoring case.

Parameters:
st - the string whose end is to be checked
with - the end string
Returns:

strIndexOfIgnoreCase

public static int strIndexOfIgnoreCase(java.lang.String txt,
                                       java.lang.String match)
Tries to locate a substring in a string while ignoring case.

Parameters:
txt -
match -
Returns:

intToStr

public static java.lang.String intToStr(int val,
                                        int radix,
                                        int npos)
Returns a number in the specified base, and with the specified #of positions. If the number is too large for the #positions then the high values are cut off.


strAddIntFixed

public static void strAddIntFixed(java.lang.Appendable sb,
                                  int val,
                                  int radix,
                                  int len)
Converts the integer to a string with a fixed length, adding leading zeroes if needed.

Parameters:
sb -
val -
radix -
len -

strCommad

public static java.lang.String strCommad(long val)
Returns a properly formatted commad string for a number [english only].

Parameters:
val -
Returns:

strDuration

public static java.lang.String strDuration(long dlt)

strDurationMillis

public static java.lang.String strDurationMillis(long dlt)

strTrunc

public static java.lang.String strTrunc(java.lang.String s,
                                        int len)

arrayToHexStr

public static void arrayToHexStr(java.lang.Appendable sb,
                                 byte[] ar,
                                 int bi,
                                 int nc,
                                 boolean fillout)
                          throws java.io.IOException
Returns a string of hex bytes for a given thing.

Throws:
java.io.IOException

arrayToAsciiStr

public static void arrayToAsciiStr(java.lang.Appendable sb,
                                   byte[] ar,
                                   int bi,
                                   int nc)
                            throws java.io.IOException
Returns a string containing only printable chars for the given bytes.

Throws:
java.io.IOException

arrayToDumpLine

public static void arrayToDumpLine(java.lang.Appendable sb,
                                   byte[] ar,
                                   int bi,
                                   int nc)
                            throws java.io.IOException
Returns a dumpstring containing the offset, the hex bytes, and the ascii representation of a given dump buffer.

Throws:
java.io.IOException

dumpData

public static void dumpData(java.lang.Appendable sb,
                            byte[] ar,
                            int off,
                            int len)
                     throws java.io.IOException
Dump the data as a formatted multiline buffer: like
        0000 ff ef aa bb cc dd 99 88  ff ef aa bb cc dd 99 88 sgdfkajse
 

Parameters:
sb -
ar -
off -
len -
Throws:
java.io.IOException

printHex

public static void printHex(java.io.PrintWriter pw,
                            byte[] arr)

printHex

public static void printHex(java.io.PrintWriter pw,
                            byte[] arr,
                            int start,
                            int end)

printHex

public static void printHex(java.io.PrintStream pw,
                            byte[] arr)

printHex

public static void printHex(java.io.PrintStream pw,
                            byte[] arr,
                            int start,
                            int end)

toHex

public static java.lang.String toHex(byte[] arr,
                                     int start,
                                     int end)
Converts the byte array passed to a hex string. This converts the region [start..end>.

Parameters:
arr - the array containing the data to convert
start - the first byte in the array to convert
end - the exclusive end of the region to convert
Returns:

toHex

public static java.lang.String toHex(byte[] arr)
Converts the byte array to a hex string.

Parameters:
arr -
Returns:

toHexSp

public static java.lang.String toHexSp(byte[] arr,
                                       int start,
                                       int end)
Converts the byte array passed to a hex string. This converts the region [start..end>.

Parameters:
arr - the array containing the data to convert
start - the first byte in the array to convert
end - the exclusive end of the region to convert
Returns:

toHexSp

public static java.lang.String toHexSp(byte[] arr)
Converts the byte array to a hex string.

Parameters:
arr -
Returns:

fromHex

public static byte[] fromHex(java.lang.String s)
                      throws java.lang.Exception
Decodes a hex string into a byte array.

Parameters:
s - the string
Returns:
the decoded array
Throws:
java.lang.Exception - if the array is malformed.

findFileOnPath

public static java.io.File findFileOnPath(java.lang.String fname,
                                          java.lang.String path)
Returns the complete filename of the first file that is found along the path specified.


findFileOnEnv

public static java.io.File findFileOnEnv(java.lang.String pname,
                                         java.lang.String env)
Finds a filename along the classpath..


getFileExtension

@Deprecated
public static java.lang.String getFileExtension(java.lang.String fn)
Deprecated. 

Returns the extension of a file. The extension includes the . If no extension is present then the empty string is returned ("").

See Also:
FileTool.getFileExtension(String)

addPathToVector

public static void addPathToVector(java.util.List<java.lang.String> v,
                                   java.lang.String p)
Adds a path to the vector specified, if the path is an existing file or directory, and it doesn't already exist in the vector.


addSearchPathToVector

public static void addSearchPathToVector(java.util.List<java.lang.String> v,
                                         java.lang.String searchpath)
Takes a search path, i.e. a list of directory/file names separated by the system path separator and adds all files/directories specified to the vector v, only if the pathname exists and if it is not already


addSearchEnvToVector

public static void addSearchEnvToVector(java.util.List<java.lang.String> v,
                                        java.lang.String envvar)
Adds the value of a "search path environment variable" to the vector.

See Also:
addSearchPathToVector()

makeSearchPath

public static void makeSearchPath(java.lang.StringBuilder sb,
                                  java.util.List<java.lang.String> v)
Returns a string buffer containing a search path variable from the vector passed.


makeSearchPath

public static java.lang.String makeSearchPath(java.util.List<java.lang.String> v)
Returns a string buffer containing a search path variable from the vector passed.


makeSearchPath

public static void makeSearchPath(java.lang.StringBuffer sb,
                                  java.lang.String[] v)
Returns a string buffer containing a search path variable from the vector passed.


makeSearchPath

public static java.lang.String makeSearchPath(java.lang.String[] v)
Returns a string buffer containing a search path variable from the vector passed.


getFinalFrom

public static java.lang.String getFinalFrom(java.lang.Class<?> cl,
                                            long sval)

getFinalFrom

public static java.lang.String getFinalFrom(java.lang.Class<?> cl,
                                            long sval,
                                            java.lang.String part)
Traverses a given class and tries to find a public


getFinalFrom

public static java.lang.String getFinalFrom(java.lang.Class<?> cl,
                                            long sval,
                                            java.lang.String part,
                                            java.lang.String ign)
Traverses a given class and tries to find a public


urlLastPart

public static java.lang.String urlLastPart(java.lang.String url)
Returns the last element (document name?) from the url passed.


htmlStringize

public static java.lang.String htmlStringize(java.lang.String is)
Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent. This allows parts of HTML to be rendered neatly.


htmlStringize

public static void htmlStringize(java.lang.StringBuilder sb,
                                 java.lang.String is)
Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent. This allows parts of HTML to be rendered neatly.


htmlStringize

public static void htmlStringize(java.lang.Appendable o,
                                 java.lang.String is)
                          throws java.lang.Exception
Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent. This allows parts of HTML to be rendered neatly.

Throws:
java.lang.Exception

xmlStringize

public static java.lang.String xmlStringize(java.lang.String is)
Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent. This allows parts of HTML to be rendered neatly.


xmlStringize

public static void xmlStringize(java.lang.StringBuffer sb,
                                java.lang.String is)
Enter with a string; it returns the same string but replaces HTML recognised characters with their &..; equivalent. This allows parts of HTML to be rendered neatly.


entitiesToUnicode

public static void entitiesToUnicode(java.lang.Appendable sb,
                                     java.lang.String str,
                                     boolean ignoremarkers)
                              throws java.io.IOException
Scans the input string for entities and replaces all entities that are actually found with their Unicode character code. The resulting string is appended to the string buffer. WARNING: this does not take HTML tah parameters into consideration!

Parameters:
sb - the buffer to append the string to
str - the string to copy while replacing entities.
Throws:
java.io.IOException

unicodeToEntities

public static void unicodeToEntities(java.lang.StringBuffer sb,
                                     java.lang.String str)
Replaces all non-ascii stuff with their entities. Also replaces <, > and &.

Parameters:
sb -
str -

entityToUnicode

public static int entityToUnicode(java.lang.String ename)
Translates an entity name to unicode. The entity can also be a numeral.

Parameters:
ename -
Returns:

strToJavascriptString

public static java.lang.String strToJavascriptString(java.lang.String cs,
                                                     boolean dblquote)

strToJavascriptString

public static void strToJavascriptString(java.lang.Appendable w,
                                         java.lang.String cs,
                                         boolean dblquote)
                                  throws java.io.IOException
Throws:
java.io.IOException

dbGetBool

public static boolean dbGetBool(java.lang.String fv)
Returns a boolean value from some database field. This returns T if the string contains T, Y, 1.


dbSetBool

public static java.lang.String dbSetBool(boolean v)
Returns a char(1) value to store in a database for booleans.


main

public static void main(java.lang.String[] args)

getEnvironment

public static java.util.List<java.lang.String> getEnvironment()
Returns the list of environment variables of the supported OS's. Because in their infinite wizdom the Java builders deprecated the use of this we need to do something complex..


getBase64Map

public static final byte[] getBase64Map()

encodeBase64

public static final java.lang.String encodeBase64(java.lang.String str)
This method encodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8). It's used for example in the "Basic" authorization scheme.

Parameters:
str - the string
Returns:
the base64-encoded str

encodeBase64

public static final byte[] encodeBase64(byte[] data)
This method encodes the given byte[] using the base64-encoding specified in RFC-2045 (Section 6.8).

Parameters:
data - the data
Returns:
the base64-encoded data

decodeBase64ToString

public static final java.lang.String decodeBase64ToString(java.lang.String str)
This method decodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8).

Parameters:
str - the base64-encoded string.
Returns:
the decoded str.

decodeBase64

public static final byte[] decodeBase64(java.lang.String str)
This method decodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8).

Parameters:
str - the base64-encoded string.
Returns:
the decoded str.

decodeBase64

public static final byte[] decodeBase64(byte[] data)
This method decodes the given byte[] using the base64-encoding specified in RFC-2045 (Section 6.8).

Parameters:
data - the base64-encoded data.
Returns:
the decoded data.

encodeBase64ToString

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

strStacktrace

public static java.lang.String strStacktrace(java.lang.Throwable t)

strStacktrace

public static void strStacktrace(java.lang.Appendable sb,
                                 java.lang.Throwable t)

strStacktraceFiltered

public static void strStacktraceFiltered(java.lang.Appendable sb,
                                         java.lang.Throwable t,
                                         java.lang.String[] skipbefore,
                                         java.lang.String[] skipafter,
                                         int linelimit)
Report a filtered location stack trace, where the start of the stack trace and the end can be removed.

Parameters:
sb -
t -
skipbefore -
skipafter -

normalizeURL

public static final java.lang.String normalizeURL(java.lang.String current,
                                                  java.lang.String tpl)
                                           throws java.lang.Exception

Called when generate() is called with a string. This must decode the string into a key object that can be used by the decodeInputURL key to determine a resource provider and a provider-relative key.

This default implementation assumes that the key is to be a normal URL string, and uses path semantics to create the actual key from the string passed: if it contains a host name it is stripped; if it is relative then the complete path is appended.

Throws:
java.lang.Exception

normalizeConcat

public static final java.lang.String normalizeConcat(java.lang.String current,
                                                     java.lang.String tpl)
                                              throws java.lang.Exception

Called when generate() is called with a string. This must decode the string into a key object that can be used by the decodeInputURL key to determine a resource provider and a provider-relative key.

This default implementation assumes that the key is to be a normal URL string, and uses path semantics to create the actual key from the string passed: if it contains a host name it is stripped; if it is relative then the complete path is appended.

Throws:
java.lang.Exception

normalizeUndot

public static final java.lang.String normalizeUndot(java.lang.String ins)
Takes an input URL and handles all '.' and '..' replacements. Any '.' sublevel is replaced by nothing (removed completely); any '..' is replaced by removing the 'upper' level and replacing that with the rest of the string.

Parameters:
ins - the input URL
Returns:
the output URL.

strToInt

public static int strToInt(java.lang.String v,
                           int defval)

strToLong

public static long strToLong(java.lang.String v,
                             long defval)

strToLong

public static long strToLong(java.lang.String v,
                             int six,
                             int eix,
                             int defval)

getNextPathComponent

public static java.lang.String getNextPathComponent(int ix,
                                                    java.lang.String s,
                                                    boolean includeslash)
Find the 1st part of the path passed, i.e. the part before the first /. If the path contains no / it returns the full path.

Parameters:
s -
Returns:

getNextPathComponent

public static java.lang.String getNextPathComponent(java.lang.String s,
                                                    boolean includeslash)

equalStringList

public static boolean equalStringList(java.util.List<java.lang.String> inl,
                                      java.util.List<java.lang.String> al,
                                      boolean caseindependent)

makeURL

public static java.lang.String makeURL(java.io.File f)
Workaround for Java bug delivering file:// instead of file:/// for file.toURL().toString().

Parameters:
f -
Returns:

fixFileURL

public static java.lang.String fixFileURL(java.lang.String fileurl)

encodeURLEncoded

public static void encodeURLEncoded(java.lang.Appendable sb,
                                    java.lang.String str)
Encode the string passed to URLEncoded format. See strDecodeURLEncoded for description of the format.

Parameters:
sb -
data -

encodeURLEncoded

public static java.lang.String encodeURLEncoded(java.lang.String str)

decodeURLEncoded

public static java.lang.String decodeURLEncoded(java.lang.String encoded)
Decode the URLEncoded string passed to a real string. An URL encoded string is obtained as follows: This code undoes the encoding and delivers the original string. If the input is badly formed the result is undefined.

Parameters:
encoded -
Returns:

getLocation

public static final java.lang.String getLocation()

getLocation

public static final void getLocation(java.lang.StringBuffer sb)

dumpLocation

public static final void dumpLocation(java.lang.String msg)

strUnquote

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

strUnspace

public static java.lang.String strUnspace(java.lang.String s)
Removes all whitespace from a string.

Parameters:
s -
Returns:

strOracleTruncate

public static java.lang.String strOracleTruncate(java.lang.String in,
                                                 int nchars)
Handles Oracle truncation rules:

Parameters:
in -
nchars -
Returns:

strNanoTime

public static java.lang.String strNanoTime(long ns)
Return a nanotime timestamp with 2 thousands of precision max.

Parameters:
ns -
Returns:

strReplace

public static java.lang.String strReplace(java.lang.String src,
                                          java.lang.String old,
                                          java.lang.String nw)
Case-sensitive replace of all occurences of [old] with [new].

Parameters:
src -
old -
nw -
Returns:

getExceptionMessage

public static java.lang.String getExceptionMessage(java.lang.Throwable t)
If the throwable passed as a message then return it verbatim, else return the exception's classname.

Parameters:
t -
Returns:

getJreVersion

public static int getJreVersion()

removeRepeatingCharacters

public static java.lang.String removeRepeatingCharacters(java.lang.String in)
Replaces long character sequences without space like ---- and ===== with a way shorter version.

Parameters:
in -
maxlen -
Returns:

extractSingleLine

public static java.lang.String extractSingleLine(java.lang.String in)
Tries to extract a single line of max. 80 chars from a memo field by scanning for a closing '.'

Parameters:
in -
Returns:

generateGUID

public static java.lang.String generateGUID()
Generate an unique identifier with reasonable expectations that it will be globally unique. This does not use the known GUID format but shortens the string by encoding into base64-like encoding.

Returns:

createInsertStatement

public static void createInsertStatement(java.lang.StringBuilder sb,
                                         java.lang.String table,
                                         java.lang.String pkname,
                                         java.lang.String pkexpr,
                                         java.lang.String[] fields)

createUpdateStatement

public static void createUpdateStatement(java.lang.StringBuilder sb,
                                         java.lang.String table,
                                         java.lang.String pkname,
                                         java.lang.String[] fields)