|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.ca.commons.cbutil.CBUtility
This is a grab bag of useful classes and static functions that are not important enough to merit being top level entities. Most of them are concerned with string handling, file handling, and i18n issues.
| Nested Class Summary | |
static class |
CBUtility.BasicWindowMonitor
A utility ftn used to make a closing window shut down the current application. |
| Method Summary | |
static java.lang.String |
byte2Hex(byte b)
|
static java.lang.String |
bytes2Hex(byte[] bytes)
|
static java.lang.String |
bytes2HexSplit(byte[] in,
int wordlength)
From Van Bui - prints out a hex string formatted with spaces between each hex word of length wordlength. |
static java.lang.String |
bytes2HexSplit(byte[] in,
int wordlength,
int linelength)
From Van Bui - prints out a hex string formatted with spaces between each hex word of length wordlength, and new lines every linelength. |
static void |
center(java.awt.Component centerMe,
java.awt.Component positioner)
This positions a component to the center of another component. |
static java.lang.String |
char2Hex(char c)
|
static void |
closeLog()
Closes the log file. |
static void |
confirm(java.lang.String Msg)
Utility function. |
static java.lang.String |
convertPathToUnix(java.lang.String dosPath)
Converts a 'dos' style file path to a unix style file path by exchanging '\' characters for for '/' characters. |
static boolean |
error(java.awt.Component owner,
java.lang.String Msg)
utility ftn; prints error message to user, and echos to the log ftn. |
static boolean |
error(java.awt.Component owner,
java.lang.String Msg,
java.lang.Exception e)
wrapper for the JFrame version of error. |
static boolean |
error(java.awt.Frame owner,
java.lang.String Msg)
utility ftn; prints error message to user, and echos to the log ftn. |
static boolean |
error(java.awt.Frame owner,
java.lang.String Msg,
java.lang.Exception e)
utility ftn; prints error message and the error to the user, and echos to the log ftn. |
static boolean |
error(java.lang.String Msg)
utility ftn; prints error message to user, and echos to the log ftn. |
static boolean |
error(java.lang.String Msg,
java.lang.Exception e)
wrapper for the JFrame version of error. |
static java.awt.Frame |
getDefaultDisplay()
|
static int |
getLogDebugLevel()
Returns the global debug level. |
static java.awt.Frame |
getParentFrame(java.awt.Component c)
Iterates through a components parents until it finds the root frame. |
static byte |
hex2Byte(char hex1,
char hex2)
|
static byte |
hexChar2Byte(char hex)
Convert a single character to a byte... |
static void |
initDefaultDisplay(java.awt.Frame owner)
|
static boolean |
isNonAsciiUTF8(byte[] sequence)
Determines whether a given byte sequence is a valid utf-8 encoding, encoding (at least in part) something *other* than normal Ascii (i.e. |
static boolean |
isUnicode(byte[] sequence)
This uses the implicit 'unicode marker' at the start of a Unicode file to determine whether a file is a unicode file. |
static boolean |
isUTF8(byte[] sequence)
Determines whether a given byte sequence is a valid utf-8 encoding. |
static void |
log(java.lang.String S)
Simple logging utility. |
static void |
log(java.lang.String S,
int level)
logs if the global debug level equal to or greater than the passed int value. |
static int |
nextCharIn(int pos,
java.lang.String searchMe,
java.lang.String compare,
boolean match)
Utility for micro-parser. |
static void |
printEnumeration(java.util.Enumeration e)
prints an enumeration... |
static java.lang.String[] |
readFilteredDirectory(java.lang.String dirPath,
java.lang.String extension)
Reads a directory, returning all file names of the given extension. |
static java.lang.String[] |
readFilteredDirectory(java.lang.String dirPath,
java.lang.String[] fileExtensions)
Reads a directory, returning all file names of the given extensions |
static java.lang.String |
readI18NByteArray(byte[] data)
|
static java.lang.String |
readI18NFile(java.io.File file)
Reads a text file, and returns the result as a StringBuffer. |
static java.util.Properties |
readPropertyFile(java.lang.String fileName)
Reads a java Properties list from a file. |
static byte[] |
readStream(java.io.InputStream is)
Reads an input stream into a byte array. |
static java.lang.String[] |
readStringArrayFile(java.lang.String fileName)
Reads an array of strings from a file (via a property file, 'cause I'm lazy). |
static java.lang.String |
readTextFile(java.io.File file)
Reads a text file, and returns the result as a StringBuffer. |
static java.lang.StringBuffer |
readURLText(java.net.URL url)
Returns the raw text (i.e. with tags as "\<...\>" strings) of a web page |
static java.lang.StringBuffer |
readURLText(java.net.URL url,
java.lang.StringBuffer errorText)
Returns the raw text (i.e. with tags as "\<...\>" strings) of a web page |
static java.lang.StringBuffer |
replaceAllBufferChar(java.lang.StringBuffer text,
char c,
java.lang.String replacement)
Deletes all characters c in text replaces it with the string replacement. |
static java.lang.StringBuffer |
replaceAllBufferString(java.lang.StringBuffer text,
java.lang.String orig,
java.lang.String replacement)
Deletes all characters c in text replaces it with the string replacement. |
static java.lang.String |
replaceAllChar(java.lang.StringBuffer text,
char c,
java.lang.String replacement)
Deletes all characters c in text replaces it with the string replacement. |
static java.lang.String |
replaceAllString(java.lang.StringBuffer text,
java.lang.String orig,
java.lang.String replacement)
Deletes all characters orig in text and replaces it with the string replacement. |
static int |
replaceChar(java.lang.StringBuffer text,
int pos,
java.lang.String replacement)
Deletes a character in text at position pos and replaces it with the string replacement. |
static int |
replaceString(java.lang.StringBuffer text,
int pos,
int len,
java.lang.String replacement)
Deletes a substring in text at position pos, of length len and replaces it with the string replacement. |
static void |
restoreCursor(java.awt.Component C)
Gets the cursor back that you just saved. |
static void |
saveCursor(java.awt.Component C)
Saves a cursor. |
static void |
setHandCursor(java.awt.Component C)
Sets the cursor to the hand cursor. |
static void |
setLogDebugLevel(int L)
Sets the level of logging on a scale of 0 (none) to 10 (everything). |
static void |
setLogType(java.lang.String logType)
Sets the type of logging, using the strings 'none', 'console' or 'file'. |
static void |
setLogType(java.lang.String logType,
java.lang.String fileName)
Sets the type of logging, using the strings 'none', 'console' or 'file'. |
static void |
setNormalCursor(java.awt.Component C)
Sets the cursor to the normal cursor. |
static void |
setWaitCursor(java.awt.Component C)
Sets the cursor to the wait cursor. |
static java.lang.String |
string2Hex(java.lang.String orig)
|
static java.lang.String |
toHTML(java.lang.String rawText)
Turns a string into HTML displayable text by escaping special characters ('<','&' etc...). ... add new ones as required; or see if an existing ftn somewhere does this already... |
static boolean |
warning(java.awt.Component caller,
java.lang.String Msg,
java.lang.String Title)
utility ftn; prints warning dialog message to the user, *without* echoing to the log ftn. |
static boolean |
warning(java.lang.String Msg)
Short version of warning method - uses default frame, and has the title 'Warning'. |
static void |
writePropertyFile(java.lang.String fileName,
java.util.Properties propertyList,
java.lang.String comments)
Writes a java Properties list to a file. |
static void |
writeStringArrayFile(java.lang.String fileName,
java.lang.String[] strings)
Writes an array of strings into a file (via a property file, 'cause I'm lazy). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public static java.lang.StringBuffer readURLText(java.net.URL url)
url - the url of the web age to read as plain text.
public static java.lang.StringBuffer readURLText(java.net.URL url,
java.lang.StringBuffer errorText)
url - the url of the web age to read as plain text.errorText - a custom message to return if something goes wrong.
public static byte[] readStream(java.io.InputStream is)
throws java.io.IOException
java.io.IOException
public static java.lang.String readTextFile(java.io.File file)
throws java.io.IOException
file - the ascii file to read from.
java.io.IOException
public static java.lang.String readI18NFile(java.io.File file)
throws java.io.IOException
This function attempts to automatically determine the encoding of the file it is to read, as either UTF-16, UTF-8, or default locale encoding, based on 1) whether the first two bytes are Unicode byte-ordering markers ('FFFE' or 'FEFF'), UTF-8 (based on whether the file is a valid UTF8 string) or, failing this, the default locale encoding.
file - the local encoding/unicode/utf8 file to read from.
java.io.IOExceptionpublic static java.lang.String readI18NByteArray(byte[] data)
public static java.lang.String[] readStringArrayFile(java.lang.String fileName)
fileName - the file to read frompublic static java.util.Properties readPropertyFile(java.lang.String fileName)
fileName - the full path and file name of the properties file
to read in.
public static void writeStringArrayFile(java.lang.String fileName,
java.lang.String[] strings)
fileName - the file to read tostrings - the array of strings
public static void writePropertyFile(java.lang.String fileName,
java.util.Properties propertyList,
java.lang.String comments)
fileName - the full path and file name of the properties file
to read in.public static java.lang.String toHTML(java.lang.String rawText)
public static int replaceChar(java.lang.StringBuffer text,
int pos,
java.lang.String replacement)
text - the text to be modifiedpos - the position of the character to be deletedreplacement - the string the character is to be replaced with.
public static java.lang.String replaceAllChar(java.lang.StringBuffer text,
char c,
java.lang.String replacement)
text - the text to be modifiedreplacement - the string the character is to be replaced with.
public static java.lang.StringBuffer replaceAllBufferChar(java.lang.StringBuffer text,
char c,
java.lang.String replacement)
text - the text to be modifiedreplacement - the string the character is to be replaced with.
public static int replaceString(java.lang.StringBuffer text,
int pos,
int len,
java.lang.String replacement)
text - the text to be modifiedpos - the position of the character to be deletedreplacement - the string the character is to be replaced with.
public static java.lang.String replaceAllString(java.lang.StringBuffer text,
java.lang.String orig,
java.lang.String replacement)
text - the text to be modifiedreplacement - the string the original substring is to be replaced with.
public static java.lang.StringBuffer replaceAllBufferString(java.lang.StringBuffer text,
java.lang.String orig,
java.lang.String replacement)
text - the text to be modifiedreplacement - the string the character is to be replaced with.
public static int nextCharIn(int pos,
java.lang.String searchMe,
java.lang.String compare,
boolean match)
pos - the position to start searching fromsearchMe - the string to searchcompare - a string containing characters to compare against
public static java.lang.String[] readFilteredDirectory(java.lang.String dirPath,
java.lang.String extension)
dirPath - directory to readextension - the file extension to filter files with.
public static java.lang.String[] readFilteredDirectory(java.lang.String dirPath,
java.lang.String[] fileExtensions)
dirPath - directory to read
public static void setWaitCursor(java.awt.Component C)
public static void setNormalCursor(java.awt.Component C)
public static void setHandCursor(java.awt.Component C)
public static void saveCursor(java.awt.Component C)
public static void restoreCursor(java.awt.Component C)
public static void setLogDebugLevel(int L)
L - the log level.public static int getLogDebugLevel()
public static void setLogType(java.lang.String logType)
logType - the type of logging to use.
public static void setLogType(java.lang.String logType,
java.lang.String fileName)
logType - the type of logging to use.public static void closeLog()
public static void log(java.lang.String S,
int level)
Log Levels
S - the string to loglevel - the debug level at which the string starts
being printedpublic static void log(java.lang.String S)
public static void initDefaultDisplay(java.awt.Frame owner)
public static java.awt.Frame getDefaultDisplay()
public static boolean error(java.awt.Component owner,
java.lang.String Msg)
public static boolean error(java.awt.Frame owner,
java.lang.String Msg)
public static boolean error(java.lang.String Msg)
public static boolean error(java.lang.String Msg,
java.lang.Exception e)
Msg - a short one line message to display to the usere - the exception to log
public static boolean error(java.awt.Component owner,
java.lang.String Msg,
java.lang.Exception e)
Msg - a short one line message to display to the usere - the exception to log
public static boolean error(java.awt.Frame owner,
java.lang.String Msg,
java.lang.Exception e)
Msg - a short one line message to display to the usere - the exception to log
public static void confirm(java.lang.String Msg)
Msg - the confirmation message to be displayed.
public static boolean warning(java.awt.Component caller,
java.lang.String Msg,
java.lang.String Title)
caller - the GUI component calling (required for dialog box drawing)Msg - a short one line message to display to the user
public static boolean warning(java.lang.String Msg)
Msg - the warning message to display.public static void printEnumeration(java.util.Enumeration e)
public static java.awt.Frame getParentFrame(java.awt.Component c)
public static java.lang.String convertPathToUnix(java.lang.String dosPath)
public static void center(java.awt.Component centerMe,
java.awt.Component positioner)
positioner - the component used as the reference center. If null,
the component will be centered on the screenpublic static java.lang.String bytes2Hex(byte[] bytes)
public static java.lang.String string2Hex(java.lang.String orig)
public static java.lang.String byte2Hex(byte b)
public static java.lang.String char2Hex(char c)
public static byte hex2Byte(char hex1,
char hex2)
public static byte hexChar2Byte(char hex)
public static java.lang.String bytes2HexSplit(byte[] in,
int wordlength)
in - input array of bytes to convertwordlength - the length of hex words to print otu.
public static java.lang.String bytes2HexSplit(byte[] in,
int wordlength,
int linelength)
in - input array of bytes to convertwordlength - the length of hex words to print otu.linelength - the length of a line to print before inserting
a line feed.public static boolean isUTF8(byte[] sequence)
Note that '7 bit ascii' is *always* a valid utf-8 string...
see rfc 2279
public static boolean isNonAsciiUTF8(byte[] sequence)
While this does not mean that the bytes *are* a utf-8 encoded string, the chance of a random byte sequence (containing bytes with the high-bit set) happening to be utf8 is roughly (1/2 ** (byte array length)).
see rfc 2279
public static boolean isUnicode(byte[] sequence)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||