public class GeneralUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.text.DecimalFormat |
PADDED_HASH_FORMAT
Used to format an Object's hashcode into a 0-padded 10 char String, e.g.
|
Constructor and Description |
---|
GeneralUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
classNameOnly(java.lang.Object o)
Given an Object instance, returns just the classname with no package
|
static java.lang.String |
classNameOnly(java.lang.String cname)
Given a String classname, returns just the classname with no package
|
static void |
dumpShortException(java.lang.Exception ex)
Dumps an exception to the console, only the last 5 lines of the stack
trace.
|
static java.lang.String |
escapeHTML(java.lang.String s)
Converts any special characters into their corresponding HTML entities , for example < to <.
|
static java.net.URL |
getURLFromClasspath(java.lang.Object obj,
java.lang.String resource) |
static java.lang.StringBuffer |
htmlEscapeSpace(java.lang.String uri) |
static java.lang.String |
inputStreamToString(java.io.InputStream is) |
static boolean |
isMacOSX() |
static void |
main(java.lang.String[] args) |
static java.io.InputStream |
openStreamFromClasspath(java.lang.Object obj,
java.lang.String resource)
Description of the Method
|
static java.lang.String |
paddedHashCode(java.lang.Object o)
Description of the Method
|
static int |
parseIntRelaxed(java.lang.String s)
Parses an integer from a string using less restrictive rules about which
characters we won't accept.
|
static java.lang.String |
trackBack(int cnt)
Returns a String tracking the last n method calls, from oldest to most
recent.
|
static void |
writeStringToFile(java.lang.String content,
java.lang.String encoding,
java.lang.String fileName) |
public static final java.text.DecimalFormat PADDED_HASH_FORMAT
public static java.io.InputStream openStreamFromClasspath(java.lang.Object obj, java.lang.String resource)
obj
- PARAMresource
- PARAMpublic static java.net.URL getURLFromClasspath(java.lang.Object obj, java.lang.String resource)
public static void dumpShortException(java.lang.Exception ex)
ex
- PARAMpublic static java.lang.String trackBack(int cnt)
trackBack()
call
from. Example:
// called from Box.calcBorders(), line 639 String tback = GeneralUtil.trackBack(6); System.out.println(tback);produces
Boxing.layoutChildren(ln 204) BlockBoxing.layoutContent(ln 81) Boxing.layout(ln 72) Boxing.layout(ln 133) Box.totalLeftPadding(ln 306) Box.calcBorders(ln 639)The
trackBack()
method itself is always excluded from the dump.
Note the output may not be useful if HotSpot has been optimizing the
code.cnt
- How far back in the call tree to go; if call tree is smaller, will
be limited to call tree.public static java.lang.String classNameOnly(java.lang.Object o)
o
- PARAMpublic static java.lang.String classNameOnly(java.lang.String cname)
cname
- PARAMpublic static java.lang.String paddedHashCode(java.lang.Object o)
o
- PARAMpublic static boolean isMacOSX()
public static java.lang.StringBuffer htmlEscapeSpace(java.lang.String uri)
public static java.lang.String inputStreamToString(java.io.InputStream is) throws java.io.IOException
java.io.IOException
public static void main(java.lang.String[] args)
public static void writeStringToFile(java.lang.String content, java.lang.String encoding, java.lang.String fileName) throws java.io.IOException, java.io.UnsupportedEncodingException
java.io.IOException
java.io.UnsupportedEncodingException
public static int parseIntRelaxed(java.lang.String s)
s
- The string to parsepublic static final java.lang.String escapeHTML(java.lang.String s)
s
- The String which may contain characters to escape.