Sharkysoft home

Class ParallelColumnsWriter


public class ParallelColumnsWriter
extends java.lang.Object

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.

Constructor Summary
ParallelColumnsWriter( 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( writer,
                             int[] col_widths)
Initialize a new ParallelColumnsWriter that writes to the specified Writer. The number of columns is col_widths.length. The width of each column is given by an integer in col_widths.
writer - the output stream
col_widths - the number and widths of the columns
Method Detail


public void writeln(java.lang.String[] text)
Enqueues lines of text into their respective columns. The lines of text are given in 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 lines
Throws: - if an I/O error occurs


public void align(boolean[] which)
Causes the indicated columns to be synchronized. In other words, all indicated columns except for the longest one will be padded with blank lines until they are the same length as the longest one. Columns are "indicated" by setting the entry in 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 indicators
Throws: - if an I/O error occurs


public void close()
Flushes buffered column data and closes the output stream.
Throws: - if an I/O error occurs

Sharkysoft home