Package apg
Class Utilities
- java.lang.Object
-
- apg.Utilities
-
public class Utilities extends java.lang.ObjectThe Utilities class defines several helper classes and static functions. These are stand-alone classes and functions that have general utility beyond the needs of any single class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUtilities.LineCatalogA class for reading a text file and cataloging its text lines.static classUtilities.XMLWriterA class for assisting in the writing of XML files.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcharArrayToString(char[] input, int offset, int length, int maxChars)Converts a subset of a character array to a String representation.static java.lang.StringcharArrayToXml(char[] input, int offset, int length)Converts a subset of a character array to XML string format.static java.lang.StringdisplayError(java.lang.Error e)Get the Error message and stack trace as a String.static java.lang.StringdisplayException(java.lang.Exception e)Get the Exception message and stack trace as a String.static voiddisplayFileInfo(java.io.PrintStream out, java.io.File file)Displays detailed information onFile.static voiddisplayFileInfo(java.io.PrintStream out, java.lang.String name)Displays detailed information on the named file.static java.io.FilegetFile(java.lang.String dir, java.lang.String filename)Return aFileobject for the named file.static java.lang.StringgetFileAsString(java.lang.String fileName)Reads the named file and returns its contents as a String.static java.lang.StringgetFileAsString(java.lang.String workingDir, java.lang.String fileName)Reads the named file and returns its contents as a String.static java.lang.Stringindent(int length)Generates a string of spaces (0x20) which is often used to provide an indent to a line of text.static java.lang.StringparserStateToString(boolean down, boolean match, int length)Converts the parser state to a String representation.
-
-
-
Method Detail
-
indent
public static java.lang.String indent(int length)
Generates a string of spaces (0x20) which is often used to provide an indent to a line of text.- Parameters:
length- the number of spaces in the indent string.- Returns:
- a String of "length" spaces
-
parserStateToString
public static java.lang.String parserStateToString(boolean down, boolean match, int length)Converts the parser state to a String representation. Used in the formatting of trace and AST displays.- Parameters:
down- iftrue, the parser direction is "down" the syntax tree - before to parsing the branch below. Iffalse, the direction is "up" after visiting the branch below.match- iftrue, the phrase was matched (may be empty)length- if match istrue, the length of the matched phrase. Zero (0) length indicates an empty phrase matched.- Returns:
- the String representation of the state.
-
charArrayToString
public static java.lang.String charArrayToString(char[] input, int offset, int length, int maxChars)Converts a subset of a character array to a String representation. Non-printing characters (not in the range32-126) are displayed as hex values (eg.x1F)- Parameters:
input- the character array to convertoffset- offset of the first character in the array subset to convert.length- the number of characters in the array subset.maxChars- imposes a maximum character length limit on the subset. If length is greater than maxChars, the subset will be truncated.- Returns:
- the String representation of the character array subset.
-
charArrayToXml
public static java.lang.String charArrayToXml(char[] input, int offset, int length)Converts a subset of a character array to XML string format.- Parameters:
input- the character array to convertoffset- offset of the first character in the array subset to convert.length- the number of characters in the array subset.- Returns:
- the XML representation of the character array subset.
-
getFileAsString
public static java.lang.String getFileAsString(java.lang.String fileName) throws java.lang.NullPointerException, java.io.FileNotFoundException, java.io.IOException, java.lang.ExceptionReads the named file and returns its contents as a String.- Parameters:
fileName- name of the file to open and read.- Returns:
- text of the file's contents.
- Throws:
java.lang.NullPointerException-Filejava.io.FileNotFoundException-Filejava.io.IOException-Filejava.lang.Exception- thrown if the named file does not exist or for some reason cannot be opened.
-
getFileAsString
public static java.lang.String getFileAsString(java.lang.String workingDir, java.lang.String fileName) throws java.lang.NullPointerException, java.io.FileNotFoundException, java.io.IOException, java.lang.ExceptionReads the named file and returns its contents as a String.- Parameters:
fileName- name of the file to open and read.workingDir- working directory to find "fileName" in.- Returns:
- text of the file's contents.
- Throws:
java.lang.NullPointerException-Filejava.io.FileNotFoundException-Filejava.io.IOException-Filejava.lang.Exception- thrown if the named file does not exist or for some reason cannot be opened.
-
getFile
public static java.io.File getFile(java.lang.String dir, java.lang.String filename)Return aFileobject for the named file.- Parameters:
dir- directory to find the file in.filename- name of the file to find.- Returns:
- the
Fileobject or null if not the file could not be found
-
displayFileInfo
public static void displayFileInfo(java.io.PrintStream out, java.lang.String name) throws java.io.IOExceptionDisplays detailed information on the named file.- Parameters:
out- the output device to display on.name- the name of the file to get information on.- Throws:
java.io.IOException- thrown if the file cannot be found or opened.
-
displayFileInfo
public static void displayFileInfo(java.io.PrintStream out, java.io.File file) throws java.io.IOExceptionDisplays detailed information onFile.- Parameters:
out- the output device to display on.file- the File to get information on.- Throws:
java.io.IOException- thrown if the file cannot be found or opened.
-
displayException
public static java.lang.String displayException(java.lang.Exception e)
Get the Exception message and stack trace as a String.- Parameters:
e- the Exception to display- Returns:
- the Exception message and stack trace as a String.
-
displayError
public static java.lang.String displayError(java.lang.Error e)
Get the Error message and stack trace as a String.- Parameters:
e- the Error to display- Returns:
- the Error message and stack trace as a String.
-
-