Package org.xhtmlrenderer.util
Class GeneralUtil
java.lang.Object
org.xhtmlrenderer.util.GeneralUtil
- Author:
- Patrick Wright
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DecimalFormatUsed to format an Object's hashcode into a 0-padded 10 char String, e.g. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringGiven an Object instance, returns just the classname with no packagestatic StringclassNameOnly(String cname) Given a String classname, returns just the classname with no packagestatic voidDumps an exception to the console, only the last 5 lines of the stack trace.static StringescapeHTML(String s) Converts any special characters into their corresponding HTML entities , for example < to <.static URLgetURLFromClasspath(Object obj, String resource) static StringBuilderhtmlEscapeSpace(String uri) static StringReads all content from a given InputStream into a String using the default platform encoding.static booleanisMacOSX()static InputStreamopenStreamFromClasspath(Object obj, String resource) static Stringstatic intParses an integer from a string using less restrictive rules about which characters we won't accept.static StringtrackBack(int cnt) Returns a String tracking the last n method calls, from oldest to most recent.static voidwriteStringToFile(String content, String encoding, String fileName)
-
Field Details
-
PADDED_HASH_FORMAT
Used to format an Object's hashcode into a 0-padded 10 char String, e.g. for 24993066 returns "0024993066"
-
-
Constructor Details
-
GeneralUtil
public GeneralUtil()
-
-
Method Details
-
openStreamFromClasspath
-
getURLFromClasspath
-
dumpShortException
Dumps an exception to the console, only the last 5 lines of the stack trace. -
trackBack
Returns a String tracking the last n method calls, from oldest to most recent. You can use this as a simple tracing mechanism to find out the calls that got to where you execute thetrackBack()call from. Example:// called from Box.calcBorders(), line 639 String tback = GeneralUtil.trackBack(6); System.out.println(tback);
producesBoxing.layoutChildren(ln 204) BlockBoxing.layoutContent(ln 81) Boxing.layout(ln 72) Boxing.layout(ln 133) Box.totalLeftPadding(ln 306) Box.calcBorders(ln 639)
ThetrackBack()method itself is always excluded from the dump. Note the output may not be useful if HotSpot has been optimizing the code.- Parameters:
cnt- How far back in the call tree to go; if call tree is smaller, will be limited to call tree.
-
classNameOnly
Given an Object instance, returns just the classname with no package -
classNameOnly
Given a String classname, returns just the classname with no package -
paddedHashCode
-
isMacOSX
public static boolean isMacOSX() -
htmlEscapeSpace
-
inputStreamToString
Reads all content from a given InputStream into a String using the default platform encoding.- Parameters:
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.- Returns:
- String containing contents read from the stream
- Throws:
IOException- if the stream could not be read
-
writeStringToFile
public static void writeStringToFile(String content, String encoding, String fileName) throws IOException - Throws:
IOException
-
parseIntRelaxed
Parses an integer from a string using less restrictive rules about which characters we won't accept. This scavenges the supplied string for any numeric character, while dropping all others.- Parameters:
s- The string to parse- Returns:
- The number represented by the passed string, or 0 if the string is null, empty, white-space only, contains only non-numeric characters, or simply evaluates to 0 after parsing (e.g. "0")
-
escapeHTML
Converts any special characters into their corresponding HTML entities , for example < to <. This is done using a character by character test, so you may consider other approaches for large documents. Make sure you declare the entities that might appear in this replacement, e.g. the latin-1 entities This method was taken from a code-samples website, written and hosted by Real Gagnon, at ....- Parameters:
s- The String which may contain characters to escape.- Returns:
- The string with the characters as HTML entities.
-