com.revusky.niggle.util
Class Util
java.lang.Object
|
+--com.revusky.niggle.util.Util
- public class Util
- extends java.lang.Object
Dumping ground for utility functions that are more or less general-purpose.
Field Summary |
static java.util.Enumeration |
EMPTY_ENUM
An empty java.util.Enumeration, comes in handy
for API's that require an Enumeration to be passed in or out. |
static java.util.Iterator |
EMPTY_ITERATOR
An empty java.util.Iterator, comes in handy
for API's that require an Iterator to be passed in or out. |
static java.lang.Integer |
ZERO
A zero integer wrapper, defined statically here to avoid replications |
Constructor Summary |
Util()
|
Method Summary |
static java.util.Enumeration |
arrayAsEnumeration(java.lang.Object[] arr)
wraps an array of objects as an instance of java.util.Enumeration
useful for API's that require an Enumeration to be passed in or out. |
static java.lang.String |
convertHTMLEntities(java.lang.String s)
Converts the literal characters in a string
to HTML entities as need be. |
static java.lang.Class |
findClass(java.lang.String className,
java.lang.ClassLoader loader)
|
static java.lang.String |
fromByteEncodedString(java.lang.String s)
|
static java.io.InputStream |
getInputStream(java.lang.String location)
Gets the specified input stream, assuming that it
may be a fully specified filename, OR relative to the
system classpath. |
static java.io.InputStream |
getInputStream(java.lang.String location,
java.lang.ClassLoader cl)
|
static boolean |
hasContent(java.lang.String s)
|
static boolean |
hasNonAscii(java.lang.String s)
A routine that says whether the given string
has unicode characters in it -- by that I mean,
characters above 0x7F, for which a naive byte encoding
will not work. |
static java.lang.String |
noNull(java.lang.String s)
|
static java.util.Iterator |
objectAsIterator(java.lang.Object o)
take a single object and wrap it up as an instance of java.util.Iterator
useful for API's that require an Iterator to be passed in or out. |
static void |
printFullStackTrace(java.lang.Throwable t,
java.io.PrintStream stream)
|
static java.lang.String |
randomAlphaNumString(int length)
|
static java.lang.String |
toByteEncodedString(java.lang.String s)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
EMPTY_ENUM
public static final java.util.Enumeration EMPTY_ENUM
- An empty java.util.Enumeration, comes in handy
for API's that require an Enumeration to be passed in or out.
EMPTY_ITERATOR
public static final java.util.Iterator EMPTY_ITERATOR
- An empty java.util.Iterator, comes in handy
for API's that require an Iterator to be passed in or out.
ZERO
public static final java.lang.Integer ZERO
- A zero integer wrapper, defined statically here to avoid replications
Util
public Util()
noNull
public static java.lang.String noNull(java.lang.String s)
- Returns:
- the zero-length string if s is null,
otherwise just echoes
hasContent
public static boolean hasContent(java.lang.String s)
- Returns:
- true if the string is null or zero-length
getInputStream
public static java.io.InputStream getInputStream(java.lang.String location)
- Gets the specified input stream, assuming that it
may be a fully specified filename, OR relative to the
system classpath.
getInputStream
public static java.io.InputStream getInputStream(java.lang.String location,
java.lang.ClassLoader cl)
findClass
public static java.lang.Class findClass(java.lang.String className,
java.lang.ClassLoader loader)
throws java.lang.ClassNotFoundException
arrayAsEnumeration
public static java.util.Enumeration arrayAsEnumeration(java.lang.Object[] arr)
- wraps an array of objects as an instance of java.util.Enumeration
useful for API's that require an Enumeration to be passed in or out.
objectAsIterator
public static java.util.Iterator objectAsIterator(java.lang.Object o)
- take a single object and wrap it up as an instance of java.util.Iterator
useful for API's that require an Iterator to be passed in or out.
printFullStackTrace
public static void printFullStackTrace(java.lang.Throwable t,
java.io.PrintStream stream)
convertHTMLEntities
public static java.lang.String convertHTMLEntities(java.lang.String s)
- Converts the literal characters in a string
to HTML entities as need be.
- Returns:
- converted string or simply echoes if no
conversion was necessary.
hasNonAscii
public static boolean hasNonAscii(java.lang.String s)
- A routine that says whether the given string
has unicode characters in it -- by that I mean,
characters above 0x7F, for which a naive byte encoding
will not work.
toByteEncodedString
public static java.lang.String toByteEncodedString(java.lang.String s)
- Returns:
- a String containing the UTF-8 encoding of
the given string.
fromByteEncodedString
public static java.lang.String fromByteEncodedString(java.lang.String s)
- Returns:
- a String containing the straight unicode chars
from previous byte encoding.
randomAlphaNumString
public static java.lang.String randomAlphaNumString(int length)