|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsofya.viewers.Viewer
public abstract class Viewer
Abstract superclass of all viewers. Defines the contract for viewers and encapsulates data members and methods shared by all classes of viewer.
Since viewer outputs are expected to be human-readable character data, all viewer classes use java.io.Writer objects internally to write data to the streams. Reading of the streams should be handled accordingly.
Field Summary | |
---|---|
protected java.io.PrintWriter |
destStream
Stream which will currently be used if no output file is specified. |
protected java.lang.String |
inputFile
Name of the file being viewed. |
protected static java.lang.String |
LINE_SEP
The system dependent newline character sequence. |
protected java.io.File |
outputFile
Name of the output file, if any. |
protected static java.io.BufferedReader |
stdin
Buffered character reader attached to System.in ,
provided for convenience. |
Constructor Summary | |
---|---|
protected |
Viewer()
Protected default constructor to prevent unsafe instantiation of viewers. |
|
Viewer(java.lang.String inputFile)
Standard constructor, creates a viewer which displays its output to the system console ( System.out ). |
|
Viewer(java.lang.String inputFile,
java.io.OutputStream stream)
Standard constructor, creates a viewer which prints its output to the specified stream. |
|
Viewer(java.lang.String inputFile,
java.lang.String outputFile)
Standard constructor, creates a viewer which prints its output to the specified file. |
Method Summary | |
---|---|
void |
print()
Prints the viewer outputs to the stream with highest precedence, ordered as follows: The specified output file, if any The specified stream, if any The System.out stream
|
abstract void |
print(java.io.PrintWriter stream)
Prints the viewer output to the specified stream - subclasses must provide the implementation for this method. |
static void |
printMethodName(java.lang.String methodName,
java.io.PrintWriter stream)
Prints a method name in a normalized human-readable format. |
static java.lang.String |
rightJust(int value,
int width)
Converts an integer to a string padded to a specified width. |
void |
setInputFile(java.lang.String fileName)
Sets the file to be viewed by this viewer. |
void |
setOutputFile(java.lang.String fileName)
Sets the name of the file to which viewer outputs should be written. |
void |
setOutputStream(java.io.OutputStream stream)
Sets the stream to which viewer outputs should be written. |
static java.lang.String |
sizeString(java.lang.String s,
int size)
Sets a string to a fixed size. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.io.BufferedReader stdin
System.in
,
provided for convenience.
protected static final java.lang.String LINE_SEP
protected java.io.PrintWriter destStream
protected java.lang.String inputFile
protected java.io.File outputFile
Constructor Detail |
---|
protected Viewer()
public Viewer(java.lang.String inputFile)
System.out
).
inputFile
- Name of the input file whose contents are being
displayed by the viewer.public Viewer(java.lang.String inputFile, java.lang.String outputFile) throws SameFileNameException, java.io.IOException
inputFile
- Name of the input file whose contents are being
displayed by the viewer.outputFile
- Name of the file to which the viewer output should
be written.
SameFileNameException
- If the specified output file and input
file are the same file.
java.io.IOException
- If there is an error creating the output file.public Viewer(java.lang.String inputFile, java.io.OutputStream stream)
Note: When using print()
, an output file
specified using setOutputFile(java.lang.String)
takes precedence over
the specified stream.
inputFile
- Name of the input file whose contents are being
displayed by the viewer.stream
- Stream to which the viewer output should be written.Method Detail |
---|
public abstract void print(java.io.PrintWriter stream) throws java.io.IOException
The stream passed to this method takes highest precedence, it
need not necessarily be any stream maintained or created internally
by the viewer. Use print()
to have the viewer select
or create a stream based on specified settings and an order of
precedence.
stream
- Stream to which the viewer outputs are to be written.
java.io.IOException
- If there is an error writing to the stream.public void setInputFile(java.lang.String fileName)
fileName
- Name of the input file whose contents are being
displayed by the viewer.public void setOutputFile(java.lang.String fileName) throws SameFileNameException, java.io.IOException
Note: When using print()
, output to file
takes precedence over any stream specified in a constructor or with
setOutputStream(java.io.OutputStream)
.
fileName
- Name of the file to which the viewer output should
be written. If null
, the viewer will use the last
specified stream, or System.out
by default.
SameFileNameException
- If the specified output file and input
file are the same file.
java.io.IOException
- If there is an error creating the output file.public void setOutputStream(java.io.OutputStream stream)
Note: When using print()
, an output file
specified using setOutputFile(java.lang.String)
takes precedence over
the specified stream.
stream
- Stream to which the viewer output should be written.public final void print() throws java.io.IOException
System.out
stream
java.io.IOException
- If there is an error writing to the stream.public static void printMethodName(java.lang.String methodName, java.io.PrintWriter stream)
methodName
- Method name to be formatted, as returned by a
BCEL method.stream
- Stream to which the normalized form is to be printed.public static java.lang.String sizeString(java.lang.String s, int size)
If the string is shorter than the requested size, it is padded with spaces (ASCII 32). If it is longer than the requested size, it is truncated.
s
- String to be resized.size
- New length to which the string is to be sized.
public static java.lang.String rightJust(int value, int width)
If the length of the integer string after conversion is less than the requested length, it is padded with spaces (ASCII 32). Otherwise it is left unchanged (it will not be truncated).
value
- Integer value to be converted to a string.width
- Required length of the string after conversion.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |