|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.Writer java.io.PrintWriter net.sf.basedb.util.export.TableWriter net.sf.basedb.util.basefile.BaseFileWriter
public class BaseFileWriter
Wraps a writer stream and provides methods for easier
creation of BASEfiles. All methods that start with
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()
.
Field Summary | |
---|---|
private String |
currentSection
|
private boolean |
dataPart
|
private boolean |
hasBom
|
private boolean |
headerPart
|
private String |
metadataPrefix
|
private Pattern |
n
|
private Pattern |
r
|
Fields inherited from class java.io.PrintWriter |
---|
out |
Fields inherited from class java.io.Writer |
---|
lock |
Constructor Summary | |
---|---|
BaseFileWriter(Writer out)
Create a new BASEfile writer that is writing it's output to the given writer. |
Method Summary | ||
---|---|---|
void |
baseBeginDataPart()
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 |
baseEndSection()
Ends the current section by writing an empty line. |
|
String |
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. |
|
|
basePrintHeader(String key,
Object value)
Prints a header in the BASEfile. |
|
void |
baseWriteBom()
Write the beginning-of-file marker (BASEfile) to the output. |
|
String |
getCurrentSection()
|
|
String |
getMetadataPrefix()
The metadata prefix is written to the beginning of each line that is not a data line. |
|
boolean |
isWritingData()
|
|
boolean |
isWritingHeaders()
|
|
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 |
---|
getDataSeparator, getEncoder, getNullValue, setDataSeparator, setEncoder, setNullValue, tableEncode, tablePrintData, tablePrintData |
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 |
---|
private String metadataPrefix
private String currentSection
private boolean hasBom
private boolean headerPart
private boolean dataPart
private Pattern r
private Pattern n
Constructor Detail |
---|
public BaseFileWriter(Writer out)
out
- The writer to write the data toMethod Detail |
---|
public String getCurrentSection()
public boolean isWritingHeaders()
public boolean isWritingData()
protected void setMode(boolean headerPart, boolean dataPart)
public String getMetadataPrefix()
Tip! Settting this value to '#' makes it possible to send a BASEfile to gnuplot.
public void setMetadataPrefix(String metaDataPrefix)
metaDataPrefix
- The new metadata prefixpublic void baseWriteBom()
public void baseBeginSection(String name)
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.
name
- The name of the sectionpublic void baseEndSection()
public <T> void basePrintHeader(String key, Object value)
key
- The header key, 'section' is not allowedvalue
- The value, if null the configured null value
is used, otherwise the toString() method is called
InvalidDataException
- If the key is 'section'public void baseBeginDataPart()
public void basePrintData(Object... data)
This call is ignored if the data part has not been started.
data
- The values to writeisWritingData()
,
baseBeginDataPart()
public String baseEscape(String in)
in
- The input string
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |