|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--lava.text.ParallelColumnsWriter
Formats data into parallel columns.
Details: A ParallelColumnsWriter
merges several streams of text into a single output stream, formatted as parallel columns. Each column flows independently of the others, except where relationships between column elements are specifically indicated.
The constructor for this class requires a Writer, which is the output stream for the merged inputs, and an array of ints, which indicate the width of each column. The length of the int array determines the total number of columns. Column data is submitted to a ParallelColumnsWriter using its write method, which accepts an array of Strings containing a line of text for each column. (Entries in the array that are set to null indicate that no data is being provided for the corresponding column.) Each column accumulates its text and formats it independently, but whenever the String array supplied to the write method contains more than one non-null entry, the lines of text given in that call are guaranteed to appear side-by-side.
The following example demonstrates the use of ParallelColumnsWriter
.
Consider the following program:
This program produces the following output:
The first five lines have already been sent to the right | line 1 column. | line 2 | line 3 | line 4 | line 5 | line 6 | line 7 | line 8 | line 9 Look at me! | line 10 | line 11 | line 12 | line 13 | line 14
Here's what happened (follow along in the code):
Constructor Summary | |
ParallelColumnsWriter(java.io.Writer writer,
int[] col_widths)
Initialize a new ParallelColumnsWriter that writes to the specified Writer. |
Method Summary | |
void |
align(boolean[] which)
Causes the indicated columns to be synchronized. |
void |
close()
Flushes buffered column data and closes the output stream. |
void |
writeln(java.lang.String[] text)
Enqueues lines of text into their respective columns. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public ParallelColumnsWriter(java.io.Writer writer, int[] col_widths)
col_widths.length
. The width of each column is given by an integer in col_widths
.writer
- the output streamcol_widths
- the number and widths of the columnsMethod Detail |
public void writeln(java.lang.String[] text) throws java.io.IOException
text
, a String
array. Note that the array's length must be equal to the number of columns specified when this instance was constructed. Elements in the array corresponding to columns for which no output is provided should be set to null
. For all non-null
entries however, the column writer will place those lines at the same depth in the output. (In other words, column lines submitted together will always appear together.) Except for this guarantee, column output is compacted as much as possible. (Note: Calls to this method will not always produce output. Output occurs only if all columns become non-empty as a result of the call.)text
- an array of text linespublic void align(boolean[] which) throws java.io.IOException
which
, the indicator array, to true
. (Note that calls to this method may result in output from the column writer, since an empty column that was "holding up" other columns may be padded as a result of this call.)which
- the column indicatorspublic void close() throws java.io.IOException
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |