2.17.2: 2011-06-17

net.sf.basedb.util.export
Class TableWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.PrintWriter
          extended by net.sf.basedb.util.export.TableWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable
Direct Known Subclasses:
AnnotationWriter, BaseFileWriter, DataWriter

public class TableWriter
extends PrintWriter

Wraps a writer stream and provides methods for easier writing of tabular data. The writer can be configured with a setDataSeparator(String) (default is 'tab'), setNullValue(String) (default is an empty string) and an setEncoder(EncoderDecoder) (no default). Use tablePrintData(Object...) to print a singe line with data. Other PrintWriter methods are not affected by those settings.

Version:
2.12
Author:
Nicklas
Last modified
$Date: 2009-11-27 14:06:17 +0100 (Fri, 27 Nov 2009) $

Field Summary
private  String dataSeparator
           
private  EncoderDecoder encoder
           
private  String nullValue
           
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
TableWriter(Writer out)
          Create a new table writer that is writing it's output to the given writer.
 
Method Summary
 String getDataSeparator()
          The data separator string is written between each data column in the output.
 EncoderDecoder getEncoder()
          Get the current default encoder for this writer.
 String getNullValue()
          The null value string is written to the output instead of null data values.
 void setDataSeparator(String dataSeparator)
          Change the data separator string.
 void setEncoder(EncoderDecoder encoder)
          Change the encoder.
 void setNullValue(String nullValue)
          Change the null value string.
 String tableEncode(String s)
          Encode the given string with the default encoder.
 void tablePrintData(EncoderDecoder encoder, Object... data)
          Print a data line to the parent writer.
 void tablePrintData(Object... data)
          Print a data line to the parent writer using the default encoder.
 
Methods inherited from class java.io.PrintWriter
append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataSeparator

private String dataSeparator

nullValue

private String nullValue

encoder

private EncoderDecoder encoder
Constructor Detail

TableWriter

public TableWriter(Writer out)
Create a new table writer that is writing it's output to the given writer.

Parameters:
out - The writer to write the data to
Method Detail

getDataSeparator

public String getDataSeparator()
The data separator string is written between each data column in the output. The default value is 'tab'.

Returns:
The current value of the data separator string

setDataSeparator

public void setDataSeparator(String dataSeparator)
Change the data separator string. Note! If this value is modified then a different encoder is probably also needed. See setEncoder(EncoderDecoder).

Parameters:
dataSeparator - The new data separator

getNullValue

public String getNullValue()
The null value string is written to the output instead of null data values. The default value is an empty string.

Returns:
The current value of the null value string

setNullValue

public void setNullValue(String nullValue)
Change the null value string.

Parameters:
nullValue - The new null value string

getEncoder

public EncoderDecoder getEncoder()
Get the current default encoder for this writer.

Returns:
The current encoder or null
Since:
2.15

setEncoder

public void setEncoder(EncoderDecoder encoder)
Change the encoder.

Parameters:
encoder - The new encoder or null to not encode
Since:
2.15

tableEncode

public String tableEncode(String s)
Encode the given string with the default encoder.

Parameters:
s - The string to encode
Returns:
The encoded string, or the argument if no default encoder has been specified
Since:
2.15

tablePrintData

public void tablePrintData(Object... data)
Print a data line to the parent writer using the default encoder.

Parameters:
data - The values to write

tablePrintData

public void tablePrintData(EncoderDecoder encoder,
                           Object... data)
Print a data line to the parent writer. Each value is separated by the data separator string ('tab' by default). Null values are replaced with the null value string (empty string by default). Non-null objects are converted to strings values by calling their toString() method and, if an encoder has been specified, then encoded with EncoderDecoder.encode(String).

Parameters:
data - The values to write
encoder - The encoder to use, or null to not use any encoder
Since:
2.15

2.17.2: 2011-06-17