public class GeneralUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static 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 String |
classNameOnly(Object o)
Given an Object instance, returns just the classname with no package
|
static String |
classNameOnly(String cname)
Given a String classname, returns just the classname with no package
|
static void |
dumpShortException(Exception ex)
Dumps an exception to the console, only the last 5 lines of the stack
trace.
|
static String |
escapeHTML(String s)
Converts any special characters into their corresponding HTML entities , for example < to <.
|
static URL |
getURLFromClasspath(Object obj,
String resource) |
static StringBuffer |
htmlEscapeSpace(String uri) |
static String |
inputStreamToString(InputStream is)
Reads all content from a given InputStream into a String using the default platform encoding.
|
static boolean |
isMacOSX() |
static InputStream |
openStreamFromClasspath(Object obj,
String resource)
Description of the Method
|
static String |
paddedHashCode(Object o)
Description of the Method
|
static int |
parseIntRelaxed(String s)
Parses an integer from a string using less restrictive rules about which
characters we won't accept.
|
static String |
trackBack(int cnt)
Returns a String tracking the last n method calls, from oldest to most
recent.
|
static void |
writeStringToFile(String content,
String encoding,
String fileName) |
public static final DecimalFormat PADDED_HASH_FORMAT
public static InputStream openStreamFromClasspath(Object obj, String resource)
obj - PARAMresource - PARAMpublic static void dumpShortException(Exception ex)
ex - PARAMpublic static 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 String classNameOnly(Object o)
o - PARAMpublic static String classNameOnly(String cname)
cname - PARAMpublic static String paddedHashCode(Object o)
o - PARAMpublic static boolean isMacOSX()
public static StringBuffer htmlEscapeSpace(String uri)
public static String inputStreamToString(InputStream is) throws IOException
is - the InputStream to read from. Must already be open, and will NOT be closed by this function. Failing to
close this stream after the call will result in a resource leak.IOException - if the stream could not be readpublic static void writeStringToFile(String content, String encoding, String fileName) throws IOException
IOExceptionpublic static int parseIntRelaxed(String s)
s - The string to parsepublic static String escapeHTML(String s)
s - The String which may contain characters to escape.Copyright © 2011-2013. All Rights Reserved.