Class BaseFileWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
base
are used for BASEfile specified formatting.
It is also possible to use the regular PrintWriter
methods for special cases.
A BASEfile is divided in sections. Each section has
a header part and a data part. To start a new section
use baseBeginSection(String)
. When a section has been
started use basePrintHeader(String, Object)
or one
of the overloaded methods to print headers for that section.
To end the header part and start the data part, use
baseBeginDataPart()
and then basePrintData(Object...)
to print data lines. When all data has been printed
either start a new section or end the current section
with baseEndSection()
.
- Version:
- 2.12
- Author:
- Nicklas
- Last modified
- $Date: 2010-08-13 10:50:27 +0200 (fr, 13 aug 2010) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate String
private boolean
private boolean
private boolean
private String
private Pattern
private Pattern
Fields inherited from class java.io.PrintWriter
out
-
Constructor Summary
ConstructorDescriptionBaseFileWriter
(Writer out) Create a new BASEfile writer that is writing it's output to the given writer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
End the header part of the current section (by writing a single % on a line by itself) and start the data part.void
baseBeginSection
(String name) Start a new section in the BASEfile.void
Ends the current section by writing an empty line.baseEscape
(String in) Escape new line and carrige return characters in the input to the literal string '\n' and '\r' in the output.void
basePrintData
(Object... data) Print a data line to the BASEfile.<T> void
basePrintHeader
(String key, Object value) Prints a header in the BASEfile.void
Write the beginning-of-file marker (BASEfile) to the output.The metadata prefix is written to the beginning of each line that is not a data line.boolean
boolean
void
setMetadataPrefix
(String metaDataPrefix) Change the metadata prefix string.protected void
setMode
(boolean headerPart, boolean dataPart) Methods inherited from class net.sf.basedb.util.export.TableWriter
getColumnFormatter, getDataSeparator, getEncoder, getNullValue, setColumnFormatter, setDataSeparator, setEncoder, setNullValue, tableEncode, tablePrintData, tablePrintData, tablePrintData, tablePrintHeaders
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.io.Writer
nullWriter
-
Field Details
-
metadataPrefix
-
currentSection
-
hasBom
private boolean hasBom -
headerPart
private boolean headerPart -
dataPart
private boolean dataPart -
r
-
n
-
-
Constructor Details
-
BaseFileWriter
Create a new BASEfile writer that is writing it's output to the given writer. The file prefix 'BASEfile' is automatically written.- Parameters:
out
- The writer to write the data to
-
-
Method Details
-
getCurrentSection
- Returns:
- The name of the current section, or null if no section has been started.
-
isWritingHeaders
public boolean isWritingHeaders()- Returns:
- TRUE if this writer is currently in the header part of a section, FALSE if no section is started or if the writer is in the data part
-
isWritingData
public boolean isWritingData()- Returns:
- TRUE if this writer is currently in the data part of a section, FALSE if no section is started or if the writer is in the header part
-
setMode
protected void setMode(boolean headerPart, boolean dataPart) -
getMetadataPrefix
The metadata prefix is written to the beginning of each line that is not a data line. The default value is an empty string.Tip! Settting this value to '#' makes it possible to send a BASEfile to gnuplot.
- Returns:
- The current value of the metadata prefix
-
setMetadataPrefix
Change the metadata prefix string.- Parameters:
metaDataPrefix
- The new metadata prefix
-
baseWriteBom
public void baseWriteBom()Write the beginning-of-file marker (BASEfile) to the output. This method must be called before it is possible to writer other data to the file. -
baseBeginSection
Start a new section in the BASEfile. If the current section hasn't been ended,baseEndSection()
is automatically called to end it. After this call the BASEfile is ready for writing headers to the new section.If the beginning-of-file-marker hasn't been written the
baseWriteBom()
is automatically called.- Parameters:
name
- The name of the section
-
baseEndSection
public void baseEndSection()Ends the current section by writing an empty line. -
basePrintHeader
Prints a header in the BASEfile. This call is ignored if no section has been started or if the current section is currently in data writing mode. Line breaks (\n) and carriage returns (\r) in the value are converted to the literal string values '\n' and '\r'.- Parameters:
key
- The header key, 'section' is not allowedvalue
- The value, if null the configured null value is used, otherwise the toString() method is called- Throws:
InvalidDataException
- If the key is 'section'
-
baseBeginDataPart
public void baseBeginDataPart()End the header part of the current section (by writing a single % on a line by itself) and start the data part. The call to this method is ignored if no section has been started or if the data part of the current section has alredy been started. -
basePrintData
Print a data line to the BASEfile. 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.This call is ignored if the data part has not been started.
- Parameters:
data
- The values to write- See Also:
-
baseEscape
Escape new line and carrige return characters in the input to the literal string '\n' and '\r' in the output.- Parameters:
in
- The input string
-