net.spy
Class SpyUtil

java.lang.Object
  extended bynet.spy.SpyUtil

public class SpyUtil
extends Object

Miscellaneous utilities.


Method Summary
static String byteAToHexString(byte[] me)
          Get a string representing the hexidecimal value of the given byte array.
static String deHTML(String contents)
          Remove HTML tags from a string.
static void dumpThreads()
          Dump the current list of threads to stderr.
static Boolean getBoolean(boolean b)
          Get a boolean instance.
static Boolean getBoolean(String s)
          Returns a Boolean with a value represented by the specified String.
static String getFileData(File file)
          Return the contents of a file as a string.
static String getFileData(String file)
          Deprecated. use getFileData(File)
static String getReaderAsString(Reader r)
          Load the contents of the given reader as a String.
static String getStack(Exception e, int skip)
          Get a stack from an exception.
static Enumeration getStackEnum(Exception e, int skip)
          Get a stack from an Exception.
static String join(Collection c, String on)
          Join a Collection of Objects on a join string.
static String join(Enumeration e, String on)
          Join an Enumeration of Strings on a join string.
static String join(Iterator i, String on)
          Join an Iterator of Objects on a join string.
static void runClass(String classname, String[] args)
          Class invoker (runs main(String[]) from a String array.
static Object[] shuffle(Object[] in)
          Shuffle (unsort) an array.
static String[] split(String on, String input)
          Split a string based on a tokenizer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

shuffle

public static Object[] shuffle(Object[] in)
Shuffle (unsort) an array.

Parameters:
in - The array of objects to shuffle.

split

public static String[] split(String on,
                             String input)
Split a string based on a tokenizer.

Parameters:
on - the string to split on (from StringTokenizer)
input - the string that needs to be split
See Also:
StringTokenizer

getFileData

public static String getFileData(String file)
                          throws IOException
Deprecated. use getFileData(File)

Throws:
IOException

getReaderAsString

public static String getReaderAsString(Reader r)
                                throws IOException
Load the contents of the given reader as a String.

Parameters:
r - a reader
Returns:
a String with the contents of the reader
Throws:
IOException

getFileData

public static String getFileData(File file)
                          throws IOException
Return the contents of a file as a string.

Parameters:
file - File to read.
Throws:
IOException - Thrown if the file cannot be opened.

join

public static String join(Enumeration e,
                          String on)
Join an Enumeration of Strings on a join string.

Parameters:
e - The enumeration
on - the join string
Returns:
a new String with all of the elements joined

join

public static String join(Iterator i,
                          String on)
Join an Iterator of Objects on a join string. Each object's toString() method will be used for stringification.

Parameters:
i - the iterator of Objects
on - the join string
Returns:
a new String with all of the elements joined

join

public static String join(Collection c,
                          String on)
Join a Collection of Objects on a join string. Each object's toString() method will be used for stringification.

Parameters:
c - the collection
on - the join string
Returns:
a String with all the elements joined

getStackEnum

public static Enumeration getStackEnum(Exception e,
                                       int skip)
Get a stack from an Exception.

Parameters:
e - Exception from which we'll be extracting the stack.
skip - Number of stack entries to skip (usually two or three)

getStack

public static String getStack(Exception e,
                              int skip)
Get a stack from an exception.

Parameters:
e - Exception from which we'll be extracting the stack.
skip - Number of stack entries to skip (usually two or three)

dumpThreads

public static void dumpThreads()
Dump the current list of threads to stderr.


byteAToHexString

public static String byteAToHexString(byte[] me)
Get a string representing the hexidecimal value of the given byte array.

Parameters:
me - the byte array that needs hexified.

runClass

public static void runClass(String classname,
                            String[] args)
                     throws Exception
Class invoker (runs main(String[]) from a String array.

Throws:
Exception

getBoolean

public static Boolean getBoolean(String s)
Returns a Boolean with a value represented by the specified String. The Boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".

Parameters:
s - the string
Returns:
the Boolean instance

getBoolean

public static Boolean getBoolean(boolean b)
Get a boolean instance.

Parameters:
b - the type of Boolean instance you want
Returns:
a shared instance of Boolean

deHTML

public static String deHTML(String contents)
Remove HTML tags from a string.

Parameters:
contents - the string whose HTML tags need removed.
Returns:
the deHTMLed string