Package net.sf.basedb.util.bfs
Class DataWriter
- java.lang.Object
-
- java.io.Writer
-
- java.io.PrintWriter
-
- net.sf.basedb.util.export.TableWriter
-
- net.sf.basedb.util.bfs.DataWriter
-
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
public class DataWriter extends TableWriter
Writer implementation for writing BFS data files. A data file is a matrix of data. Columns are separated by tabs. Values are escaped using the regular rules (TabCrLfEncoderDecoder
). All rows must have an equal number of columns. The number of columns is defined by the first call tobfsPrintData(Object...)
or by callingsetColumnCount(int)
.- Version:
- 2.15
- Author:
- Nicklas
- Last modified
- $Date: 2019-05-21 13:37:09 +0200 (tis, 21 maj 2019) $
-
-
Field Summary
Fields Modifier and Type Field Description private int
columnCount
private String
filename
private boolean
lockedColumns
-
Fields inherited from class java.io.PrintWriter
out
-
-
Constructor Summary
Constructors Constructor Description DataWriter(Writer out)
Create a new BFS data writer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bfsPrintData(Object... data)
Print a data line.static DataWriter
create(File file)
Utility method for creating a data writer to a file in the native file system.static DataWriter
create(OutputStream out, String filename)
Utility method for creating a data writer when you have an output stream.static DataWriter
create(File file)
Utility method for creating a data writer to a file in the BASE file system.int
getColumnCount()
Get the number of data columns.String
getFilename()
Get the file name that this writer is printing to.boolean
isLockedColumns()
Checks if the number of columns has been locked or not.void
setColumnCount(int columns)
Set the number of data columns.void
setFilename(String filename)
Set the file name that this writer is printing to.-
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 Detail
-
filename
private String filename
-
lockedColumns
private boolean lockedColumns
-
columnCount
private int columnCount
-
-
Constructor Detail
-
DataWriter
public DataWriter(Writer out)
Create a new BFS data writer.- Parameters:
out
- The parent writer which this writer will print to
-
-
Method Detail
-
create
public static DataWriter create(OutputStream out, String filename)
Utility method for creating a data writer when you have an output stream.- Parameters:
out
- The output stream the writer should print tofilename
- Optional, the name of the file the output stream is printing to
-
create
public static DataWriter create(File file)
Utility method for creating a data writer to a file in the BASE file system. The character set and MIME type on the file are automatically updated.- Parameters:
file
- The file in the BASE file system
-
create
public static DataWriter create(File file) throws IOException
Utility method for creating a data writer to a file in the native file system. If the file doesn't exists, it is created.- Parameters:
file
- The file in the native file system- Throws:
IOException
-
getFilename
public String getFilename()
Get the file name that this writer is printing to.- Returns:
- The file name or null if not known
-
setFilename
public void setFilename(String filename)
Set the file name that this writer is printing to.
-
getColumnCount
public int getColumnCount()
Get the number of data columns. This information is only available after the first line of data has been printed or if a specific number of columns has been set.- Returns:
- The number of columns, or -1 if this information is not yet known
-
setColumnCount
public void setColumnCount(int columns)
Set the number of data columns. This can only be changed as long as no data has been written to the stream.- Parameters:
columns
- The number of data columns, if 0 or negative the first call tobfsPrintData(Object...)
determines the number of columns
-
isLockedColumns
public boolean isLockedColumns()
Checks if the number of columns has been locked or not. The number of required columns are locked the first time a call tobfsPrintData(Object...)
is made.
-
bfsPrintData
public void bfsPrintData(Object... data)
Print a data line. The number of columns must be the same for all calls to this method. Normally, the first call determines the required number of columns, but this can also be set withsetColumnCount(int)
.- Parameters:
data
- The data to print- Throws:
IllegalStateException
- If headers has not been printedIllegalArgumentException
- If the data array doesn't match the required number of columnsNullPointerException
- If the data array is null
-
-