com.pegacat.vcf.utility
Class Utility

java.lang.Object
  |
  +--com.pegacat.vcf.utility.Utility

public class Utility
extends java.lang.Object

Usefully thingumies that don't rate their own classes wind up in here...


Method Summary
static java.lang.String byte2Hex(byte b)
           
static java.lang.String bytes2Hex(byte[] bytes)
           
static void center(java.awt.Component centerMe, java.awt.Component positioner)
          This positions a component to the center of another component.
static void centerOnScreen(java.awt.Component centerMe)
          Centers the compenent on the screen
static java.lang.String char2Hex(char c)
           
static java.awt.Frame getParentFrame(java.awt.Component c)
          Iterates through a components parents until it finds the root frame.
static int nextCharIn(int pos, java.lang.String searchMe, java.lang.String compare, boolean match)
          Get the next character pos in a string after an initial offset that either matches, or does not match, any of a set of comparison characters.
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 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.
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 c in text 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 java.lang.String string2Hex(java.lang.String orig)
           
static void writeTextFile(java.io.File file, java.lang.String data)
          Writes a String to a text file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readURLText

public static java.lang.StringBuffer readURLText(java.net.URL url)
                                          throws java.io.IOException
Returns the raw text (i.e. with tags as "\<...\>" strings) of a web page
Parameters:
url - the url of the web age to read as plain text.
Returns:
a StringBuffer containing the raw html text

readTextFile

public static java.lang.String readTextFile(java.io.File file)
                                     throws java.io.IOException
Reads a text file, and returns the result as a StringBuffer. Not Recommended for large (say > 100k) files.
Parameters:
file - the ascii file to read from.

writeTextFile

public static void writeTextFile(java.io.File file,
                                 java.lang.String data)
                          throws java.io.IOException
Writes a String to a text file.
Parameters:
file - the ascii file to read from.

replaceChar

public 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.
Parameters:
text - the text to be modified
pos - the position of the character to be deleted
replacement - the string the character is to be replaced with.

replaceAllChar

public 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.
Parameters:
text - the text to be modified
replacement - the string the character is to be replaced with.

replaceAllBufferChar

public 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.
Parameters:
text - the text to be modified
replacement - the string the character is to be replaced with.

replaceString

public 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.
Parameters:
text - the text to be modified
pos - the position of the character to be deleted
replacement - the string the character is to be replaced with.

replaceAllString

public static java.lang.String replaceAllString(java.lang.StringBuffer text,
                                                java.lang.String orig,
                                                java.lang.String replacement)
Deletes all characters c in text replaces it with the string replacement.
Parameters:
text - the text to be modified
replacement - the string the original substring is to be replaced with.

replaceAllBufferString

public 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.
Parameters:
text - the text to be modified
replacement - the string the character is to be replaced with.

nextCharIn

public static int nextCharIn(int pos,
                             java.lang.String searchMe,
                             java.lang.String compare,
                             boolean match)
Get the next character pos in a string after an initial offset that either matches, or does not match, any of a set of comparison characters.
Parameters:
pos - the position to start searching from
searchMe - the string to search
compare - a string containing characters to compare against
whether - the match is for characters in the compare string (true) or not in the compare string (false)
Returns:
the position found, or -1 if no position is found.

readFilteredDirectory

public static java.lang.String[] readFilteredDirectory(java.lang.String dirPath,
                                                       java.lang.String extension)
Reads a directory, returning all file names of the given extension.
Parameters:
dirPath - directory to read
extension - the file extension to filter files with.
Returns:
list of full file names

readFilteredDirectory

public static java.lang.String[] readFilteredDirectory(java.lang.String dirPath,
                                                       java.lang.String[] fileExtensions)
Reads a directory, returning all file names of the given extensions
Parameters:
dirPath - directory to read
extension - a list of file extensions to filter files with. A 'null' means 'a directory' use an empty string for blank extension files).
Returns:
list of full file names

printEnumeration

public static void printEnumeration(java.util.Enumeration e)
prints an enumeration...

getParentFrame

public static java.awt.Frame getParentFrame(java.awt.Component c)
Iterates through a components parents until it finds the root frame. Useful for initing JDialogs etc. that require a root frame to work properly.

center

public static void center(java.awt.Component centerMe,
                          java.awt.Component positioner)
This positions a component to the center of another component. If both components are showing on the sceen, it uses absolute screen co-ordinates, otherwise if only the positioner component is showing, it uses relative co-ordinates (since it is unable to obtain screen co-ords). If the components share a reference frame, these two actions are equivalent (i.e. if they both have the same parent). If nothing is showing, the component is unchanged.
Parameters:
centreMe - the component to center
positioner - the component used as the reference center.

centerOnScreen

public static void centerOnScreen(java.awt.Component centerMe)
Centers the compenent on the screen
Parameters:
centerMe - the awt derived component to center.

bytes2Hex

public static java.lang.String bytes2Hex(byte[] bytes)

string2Hex

public static java.lang.String string2Hex(java.lang.String orig)

byte2Hex

public static java.lang.String byte2Hex(byte b)

char2Hex

public static java.lang.String char2Hex(char c)