org.eaglei.datatools.etl.utils
Class BasicUtils

java.lang.Object
  extended by org.eaglei.datatools.etl.utils.BasicUtils

public class BasicUtils
extends java.lang.Object

Title: BasicUtils

Description: A collection of basic functions for standard operations like saving a string to file, and centering a frame

Copyright: Copyright (c) 2003

Company: Mindswap (http://www.mindswap.org)

Version:
1.0
Author:
Michael Grove

Constructor Summary
BasicUtils()
           
 
Method Summary
static void centerFrame(java.awt.Window theParent, java.awt.Window theFrame)
          Centers a frame with respect to another window, or the whole screen
static java.util.Set collectElements(java.util.Iterator theIter)
          Returns the list of elements returned by an iterator in a Set
static boolean containsAny(java.util.Set theList, java.util.Set toSearch)
          Checks to see if any elements of one set are present in another.
static java.lang.String convertStringToUnicodeString(java.lang.String s)
          Converts a regular java string to its unicode string representation

static java.net.URL encode(java.net.URL theURL)
          Encodes the specified URL, changes spaces to %20
static java.lang.String getFileAsString(java.lang.String fn)
          Given a path to a file on the local disk, return the contents of that file as a String.

static java.lang.String getRandomString()
          Returns a randomly generated string of up to 15 characters.

static java.lang.String getRandomString(int numChars)
          Returns a randomly generated string of up to X characters.

static java.lang.String getStringFromBufferedReader(java.io.BufferedReader aReader)
          Read the contents of the specified reader return them as a String
static java.awt.Image getTranslucentVersionOf(java.awt.Image img)
          Changes an images alpha values to the specified value.
static java.lang.String getURLAsString(java.net.URL theURL)
          Returns the specified URL as a string.
static java.lang.String hexEntityStringConvert(java.lang.String theString)
          Converts any hex entity type chars ("é") to their ascii equivalent
static boolean isFileURL(java.lang.String s)
          Returns string if the parameter represents a valid file URL
static boolean isInArray(int elem, int[] array)
          Returns true or false depending on whether or not the specified string is in the array.
static boolean isValidURL(java.lang.String s)
          Returns whether or not the parameter is a valid URL
static java.lang.String replace(java.lang.String host, java.lang.String oldchar, java.lang.String newchar)
          Given a string, replace all occurances of one string with another.

static void saveStringToFile(java.lang.String toSave, java.lang.String fn)
          Save the specifed string to the given file name
static void toFrontHack(javax.swing.JFrame theParent, javax.swing.JFrame theFrame)
          Moves a frame in front of another frame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicUtils

public BasicUtils()
Method Detail

getFileAsString

public static java.lang.String getFileAsString(java.lang.String fn)
                                        throws java.io.IOException,
                                               java.io.FileNotFoundException
Given a path to a file on the local disk, return the contents of that file as a String.

Parameters:
fn - Fully qualified file name to a file on the local disk
Returns:
Contents of the file as a String
Throws:
java.io.IOException - if there are problems opening or reading from the file
java.io.FileNotFoundException - if the file cannot be found

getURLAsString

public static java.lang.String getURLAsString(java.net.URL theURL)
                                       throws java.io.IOException
Returns the specified URL as a string. This function will read the contents at the specified URl and return the results.

Parameters:
theURL - URL the URL to read from
Returns:
String the String found at the URL
Throws:
java.io.IOException

encode

public static java.net.URL encode(java.net.URL theURL)
Encodes the specified URL, changes spaces to %20

Parameters:
theURL - URL the url to encode
Returns:
URL the encoded url

getStringFromBufferedReader

public static java.lang.String getStringFromBufferedReader(java.io.BufferedReader aReader)
                                                    throws java.io.IOException
Read the contents of the specified reader return them as a String

Parameters:
aReader - BufferedReader the reader to read from
Returns:
String the string contained in the reader
Throws:
java.io.IOException

saveStringToFile

public static void saveStringToFile(java.lang.String toSave,
                                    java.lang.String fn)
                             throws java.io.IOException,
                                    java.io.FileNotFoundException
Save the specifed string to the given file name

Parameters:
toSave - String the string to save
fn - String the file to save the string to
Throws:
java.io.IOException
java.io.FileNotFoundException

getRandomString

public static java.lang.String getRandomString()
Returns a randomly generated string of up to 15 characters.

Returns:
A randomly generated string

getRandomString

public static java.lang.String getRandomString(int numChars)
Returns a randomly generated string of up to X characters.

Parameters:
numChars - the number of characters long the random string should be
Returns:
A randomly generated string

isValidURL

public static boolean isValidURL(java.lang.String s)
Returns whether or not the parameter is a valid URL

Parameters:
s - String - the url to test
Returns:
boolean - true if the parameter is a valid url, false otherwise

isFileURL

public static boolean isFileURL(java.lang.String s)
Returns string if the parameter represents a valid file URL

Parameters:
s - String the url
Returns:
boolean true if it is a valid file URL, false otherwise

isInArray

public static boolean isInArray(int elem,
                                int[] array)
Returns true or false depending on whether or not the specified string is in the array.

Parameters:
elem - int to search for
array - int array to search through
Returns:
true if elem is in array, false otherwise

convertStringToUnicodeString

public static java.lang.String convertStringToUnicodeString(java.lang.String s)
                                                     throws java.lang.Exception
Converts a regular java string to its unicode string representation

Parameters:
s - Java String to convert to unicode
Returns:
the converted string
Throws:
java.lang.Exception

hexEntityStringConvert

public static java.lang.String hexEntityStringConvert(java.lang.String theString)
Converts any hex entity type chars ("é") to their ascii equivalent

Parameters:
theString - String the string to conver
Returns:
String the converted string

toFrontHack

public static void toFrontHack(javax.swing.JFrame theParent,
                               javax.swing.JFrame theFrame)
Moves a frame in front of another frame

Parameters:
theParent - JFrame the parent, or reference frame
theFrame - JFrame the frame to move in front

centerFrame

public static void centerFrame(java.awt.Window theParent,
                               java.awt.Window theFrame)
Centers a frame with respect to another window, or the whole screen

Parameters:
theParent - Window the reference (parent) frame, or null to center on the entire screen
theFrame - Window the window to center

containsAny

public static boolean containsAny(java.util.Set theList,
                                  java.util.Set toSearch)
Checks to see if any elements of one set are present in another. First parameter is the list of elements to search for, the second parameter is the list to search in. Basically tests to see if the two sets intersect

Parameters:
theList - Set the elements to look for
toSearch - Set the search set
Returns:
boolean true if any element in the first set is present in the second

collectElements

public static java.util.Set collectElements(java.util.Iterator theIter)
Returns the list of elements returned by an iterator in a Set

Parameters:
theIter - Iterator
Returns:
Set

getTranslucentVersionOf

public static java.awt.Image getTranslucentVersionOf(java.awt.Image img)
Changes an images alpha values to the specified value. Works on Windows platforms only.

Parameters:
img - Image to fade
Returns:
copy of the image with reduced alpha values

replace

public static java.lang.String replace(java.lang.String host,
                                       java.lang.String oldchar,
                                       java.lang.String newchar)
Given a string, replace all occurances of one string with another.

Parameters:
host - parent string
oldchar - String to remove
newchar - String to insert in the place of oldchar in the String host
Returns:
copy of host with all occurances of param oldchar replaced with param newchar


Copyright © 2009-2010 Eagle-I. All Rights Reserved.