public class TableWriter extends FilterWriter
'\t'
) and rows are separated by line terminators ('\r'
, '\n'
or "\r\n"
). Every table's cells are stored in memory until flush()
is invoked. When invoked, 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.
...produces the following output: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();
Prénom Nom --------- ------- Idéphonse Laporte Sarah Coursi Yvan Dubois
Modifier and Type | Field and Description |
---|---|
static int |
ALIGN_CENTER
A possible value for cell alignment.
|
static int |
ALIGN_LEFT
A possible value for cell alignment.
|
static int |
ALIGN_RIGHT
A possible value for cell alignment.
|
static char |
DOUBLE_HORIZONTAL_LINE
A line separator for .
|
static String |
DOUBLE_VERTICAL_LINE
A column separator for constructor.
|
static char |
SINGLE_HORIZONTAL_LINE
A line separator for .
|
static String |
SINGLE_VERTICAL_LINE
A column separator for constructor.
|
out
Constructor and Description |
---|
TableWriter(Writer out)
Creates a new table writer with a default column separator.
|
TableWriter(Writer out,
int spaces)
Creates a new table writer with the specified amount of spaces as column separator.
|
TableWriter(Writer out,
String separator)
Creates a new table writer with the specified column separator.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Flushs the table content and close the underlying stream.
|
void |
flush()
Flushs the table content to the underlying stream.
|
int |
getAlignment()
Returns the alignment for current and next cells.
|
int |
getColumnCount()
Returns the number of columns in this table.
|
int |
getRowCount()
Returns the number of rows in this table.
|
boolean |
isMultiLinesCells()
Tells if EOL characters are used for line feeds inside current cells.
|
void |
nextColumn()
Moves one column to the right.
|
void |
nextColumn(char fill)
Moves one column to the right.
|
void |
nextLine()
Moves to the first column on the next row.
|
void |
nextLine(char fill)
Moves to the first column on the next row.
|
void |
setAlignment(int alignment)
Sets the alignment for current and next cells.
|
void |
setColumnAlignment(int column,
int alignment)
Sets the alignment for all cells in the specified column.
|
void |
setMultiLinesCells(boolean multiLines)
Sets the desired behavior for EOL and tabulations characters.
|
String |
toString()
Returns the table content as a string.
|
void |
write(char[] cbuf)
Writes an array of characters.
|
void |
write(char[] cbuf,
int offset,
int length)
Writes a portion of an array of characters.
|
void |
write(int c)
Write a single character.
|
void |
write(String string)
Writes a string.
|
void |
write(String string,
int offset,
int length)
Writes a portion of a string.
|
void |
writeHorizontalSeparator()
Writes an horizontal separator.
|
public static final int ALIGN_LEFT
public static final int ALIGN_RIGHT
public static final int ALIGN_CENTER
public static final String SINGLE_VERTICAL_LINE
public static final String DOUBLE_VERTICAL_LINE
public static final char SINGLE_HORIZONTAL_LINE
public static final char DOUBLE_HORIZONTAL_LINE
public TableWriter(Writer out)
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.
out
- Writer object to provide the underlying stream, or null
if there is no
underlying stream. If out
is null, then the toString()
method is the only
way to get the table's content.public TableWriter(Writer out, int spaces)
out
- Writer object to provide the underlying stream, or null
if there is no
underlying stream. If out
is null, then the toString()
method is the only
way to get the table's content.spaces
- Amount of white spaces to use as column separator.public TableWriter(Writer out, String separator)
out
- Writer object to provide the underlying stream, or null
if there is no
underlying stream. If out
is null, then the toString()
method is the only
way to get the table's content.separator
- String to write between columns. Drawing box characters are treated
specially. For example " \\u2502 "
can be used for a single-line box.SINGLE_VERTICAL_LINE
,
DOUBLE_VERTICAL_LINE
public void setMultiLinesCells(boolean multiLines)
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.
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 nextColumn()
and nextLine()
calls respectively).
false
.multiLines
- true
true if EOL are used for line feeds inside current cells, or
false
if EOL move to the next row.public boolean isMultiLinesCells()
true
if EOL characters are to be write inside the cell.public void setColumnAlignment(int column, int alignment)
column
- The 0-based column number.alignment
- Cell alignment. Must be ALIGN_LEFT
ALIGN_RIGHT
or ALIGN_CENTER
.public void setAlignment(int alignment)
ALIGN_LEFT
.alignment
- Cell alignment. Must be ALIGN_LEFT
ALIGN_RIGHT
or ALIGN_CENTER
.public int getAlignment()
ALIGN_LEFT
(the default), ALIGN_RIGHT
or ALIGN_CENTER
.public int getRowCount()
flush()
.public int getColumnCount()
public void write(int c)
isMultiLinesCells()
is false
(which is the
default), then:
'\t'
) are replaced by nextColumn()
invocations.
'\r'
, '\n'
or "\r\n"
) are
replaced by nextLine()
invocations.
write
in class FilterWriter
c
- Character to write.public void write(String string)
write(int)
.public void write(String string, int offset, int length)
write(int)
.write
in class FilterWriter
string
- String to write.offset
- Offset from which to start writing characters.length
- Number of characters to write.public void write(char[] cbuf)
write(int)
.public void write(char[] cbuf, int offset, int length)
write(int)
.write
in class FilterWriter
cbuf
- Array of characters.offset
- Offset from which to start writing characters.length
- Number of characters to write.public void writeHorizontalSeparator()
public void nextColumn()
public void nextColumn(char fill)
nextColumn('*')
from the first character of a cell is a
convenient way to put a pad value in this cell.fill
- Character filling the cell (default to whitespace).public void nextLine()
public void nextLine(char fill)
nextLine('-')
from the first column of a row is a convenient way to fill this
row with a line separator.fill
- Character filling the rest of the line (default to whitespace). This caracter may
be use as a row separator.SINGLE_HORIZONTAL_LINE
,
DOUBLE_HORIZONTAL_LINE
public void flush() throws IOException
flush
in interface Flushable
flush
in class FilterWriter
IOException
- if an output operation failed.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class FilterWriter
IOException
- if an output operation failed.Copyright © 1996–2019 Geotools. All rights reserved.