| java.lang.Object java.io.Writer java.io.FilterWriter org.geotools.io.TableWriter
TableWriter | public class TableWriter extends FilterWriter (Code) | | A character stream that can be used to format tables. Columns are separated
by tabulations ('\t' ) and rows are separated by line terminators
('\r' , '\n' or "\r\n" ). Every table's
cells are stored in memory until
TableWriter.flush() is invoked. When invoked,
TableWriter.flush() copy cell's contents to the underlying stream while replacing
tabulations by some amount of spaces. The exact number of spaces is computed
from cell's widths.
TableWriter produces correct output when
displayed with a monospace font.
For example, the following code...
TableWriter out = new TableWriter(new OutputStreamWriter(System.out), 3);
out.write("Prénom\tNom\n");
out.nextLine('-');
out.write("Idéphonse\tLaporte\nSarah\tCoursi\nYvan\tDubois");
out.flush();
...produces the following output:
Prénom Nom
--------- -------
Idéphonse Laporte
Sarah Coursi
Yvan Dubois
since: 2.0 version: $Id: TableWriter.java 22691 2006-11-10 22:30:28Z desruisseaux $ author: Martin Desruisseaux |
Field Summary | |
final public static int | ALIGN_CENTER A possible value for cell alignment. | final public static int | ALIGN_LEFT A possible value for cell alignment. | final public static int | ALIGN_RIGHT A possible value for cell alignment. |
Constructor Summary | |
public | TableWriter(Writer out) Creates a new table writer with a default column separator. | public | TableWriter(Writer out, int spaces) Creates a new table writer with the specified
amount of spaces as column separator. | public | TableWriter(Writer out, String separator) Creates a new table writer with the specified column separator.
Parameters: out - Writer object to provide the underlying stream,or null if there is no underlying stream.If out is null, then the TableWriter.toStringmethod is the only way to get the table's content. Parameters: separator - String to write between columns. |
Method Summary | |
public void | close() Flush the table content and close the underlying stream. | public void | flush() Flush the table content to the underlying stream. | public int | getAlignment() Returns the alignment for current and next cells. | public boolean | isMultiLinesCells() Tells if EOL characters are used for line feeds inside current cells. | public void | nextColumn() Moves one column to the right. | public void | nextColumn(char fill) Moves one column to the right. | public void | nextLine() Moves to the first column on the next row. | public void | nextLine(char fill) Moves to the first column on the next row. | public void | setAlignment(int alignment) Set the alignment for current and next cells. | public void | setColumnAlignment(int column, int alignment) Set the alignment for all cells in the specified column. | public void | setMultiLinesCells(boolean multiLines) Set the desired behavior for EOL and tabulations characters.
- If
true , EOL (
'\r' , '\n' or
"\r\n" ) and tabulations ('\t' ) characters
are copied straight into the current cell, which mean that next write
operations will continue inside the same cell.
- If
false , then tabulations move to next column and EOL move
to the first cell of next row (i.e.
| public String | toString() Returns the table content as a string. | public void | write(int c) Write a single character. | public void | write(String string) Write a string. | public void | write(String string, int offset, int length) Write a portion of a string. | public void | write(char cbuf) Write an array of characters. | public void | write(char cbuf, int offset, int length) Write a portion of an array of characters. | public void | writeHorizontalSeparator() Write an horizontal separator. |
ALIGN_CENTER | final public static int ALIGN_CENTER(Code) | | A possible value for cell alignment. This
specifies that the text is aligned to the center
and extra whitespace should be placed equally on
the left and right.
|
ALIGN_LEFT | final public static int ALIGN_LEFT(Code) | | A possible value for cell alignment. This
specifies that the text is aligned to the left
indent and extra whitespace should be placed on
the right.
|
ALIGN_RIGHT | final public static int ALIGN_RIGHT(Code) | | A possible value for cell alignment. This
specifies that the text is aligned to the right
indent and extra whitespace should be placed on
the left.
|
TableWriter | public TableWriter(Writer out)(Code) | | Creates a new table writer with a default column separator.
Note: this writer may produces bad output on Windows console,
unless the underlying stream use the correct codepage (e.g.
OutputStreamWriter(System.out, "Cp437") ).
To display the appropriate codepage for a Windows NT console,
type
chcp on the command line.
Parameters: out - Writer object to provide the underlying stream,or null if there is no underlying stream.If out is null, then the TableWriter.toStringmethod is the only way to get the table's content. |
TableWriter | public TableWriter(Writer out, int spaces)(Code) | | Creates a new table writer with the specified
amount of spaces as column separator.
Parameters: out - Writer object to provide the underlying stream,or null if there is no underlying stream.If out is null, then the TableWriter.toStringmethod is the only way to get the table's content. Parameters: spaces - Amount of white spaces to use as column separator. |
TableWriter | public TableWriter(Writer out, String separator)(Code) | | Creates a new table writer with the specified column separator.
Parameters: out - Writer object to provide the underlying stream,or null if there is no underlying stream.If out is null, then the TableWriter.toStringmethod is the only way to get the table's content. Parameters: separator - String to write between columns. Drawing box charactersare treated specially. For example " \\u2502 " can beused for a single-line box. |
close | public void close() throws IOException(Code) | | Flush the table content and close the underlying stream.
throws: IOException - if an output operation failed. |
flush | public void flush() throws IOException(Code) | | Flush the table content to the underlying stream.
This method should not be called before the table
is completed (otherwise, columns may have the
wrong width).
throws: IOException - if an output operation failed. |
isMultiLinesCells | public boolean isMultiLinesCells()(Code) | | Tells if EOL characters are used for line feeds inside current cells.
|
nextColumn | public void nextColumn()(Code) | | Moves one column to the right. Next write
operations will occur in a new cell on the
same row.
|
nextColumn | public void nextColumn(char fill)(Code) | | Moves one column to the right. Next write operations will occur in a
new cell on the same row. This method fill every remaining space in
the current cell with the specified character. For example calling
nextColumn('*') from the first character of a cell is
a convenient way to put a pad value in this cell.
Parameters: fill - Character filling the cell (default to whitespace). |
nextLine | public void nextLine()(Code) | | Moves to the first column on the next row.
Next write operations will occur on a new row.
|
nextLine | public void nextLine(char fill)(Code) | | Moves to the first column on the next row. Next write operations will
occur on a new row. This method fill every remaining cell in the current
row with the specified character. Calling nextLine('-')
from the first column of a row is a convenient way to fill this row
with a line separator.
Parameters: fill - Character filling the rest of the line(default to whitespace). This caracter maybe use as a row separator. |
setColumnAlignment | public void setColumnAlignment(int column, int alignment)(Code) | | Set the alignment for all cells in the specified column. This method
overwrite the alignment for all previous cells in the specified column.
Parameters: column - The 0-based column number. Parameters: alignment - Cell alignment. Must be TableWriter.ALIGN_LEFTTableWriter.ALIGN_RIGHT or TableWriter.ALIGN_CENTER. |
setMultiLinesCells | public void setMultiLinesCells(boolean multiLines)(Code) | | Set the desired behavior for EOL and tabulations characters.
- If
true , EOL (
'\r' , '\n' or
"\r\n" ) and tabulations ('\t' ) characters
are copied straight into the current cell, which mean that next write
operations will continue inside the same cell.
- If
false , then tabulations move to next column and EOL move
to the first cell of next row (i.e. tabulation and EOL are equivalent to
TableWriter.nextColumn() and
TableWriter.nextLine() calls respectively).
The default value is
false .
Parameters: multiLines - true true if EOL are used for line feeds insidecurrent cells, or false if EOL move to the next row. |
toString | public String toString()(Code) | | Returns the table content as a string.
|
write | public void write(String string)(Code) | | Write a string. Tabulations and line separators
are interpreted as by
TableWriter.write(int) .
Parameters: string - String to write. |
write | public void write(String string, int offset, int length)(Code) | | Write a portion of a string. Tabulations and line
separators are interpreted as by
TableWriter.write(int) .
Parameters: string - String to write. Parameters: offset - Offset from which to start writing characters. Parameters: length - Number of characters to write. |
write | public void write(char cbuf)(Code) | | Write an array of characters. Tabulations and line
separators are interpreted as by
TableWriter.write(int) .
Parameters: cbuf - Array of characters to be written. |
write | public void write(char cbuf, int offset, int length)(Code) | | Write a portion of an array of characters. Tabulations and
line separators are interpreted as by
TableWriter.write(int) .
Parameters: cbuf - Array of characters. Parameters: offset - Offset from which to start writing characters. Parameters: length - Number of characters to write. |
writeHorizontalSeparator | public void writeHorizontalSeparator()(Code) | | Write an horizontal separator.
|
|
|