Package net.sf.basedb.util.bfs
Class AnnotationWriter
- java.lang.Object
-
- java.io.Writer
-
- java.io.PrintWriter
-
- net.sf.basedb.util.export.TableWriter
-
- net.sf.basedb.util.bfs.AnnotationWriter
-
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
public class AnnotationWriter extends TableWriter
- 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
hasPrintedHeaders
private Set<Integer>
usedIds
-
Fields inherited from class java.io.PrintWriter
out
-
-
Constructor Summary
Constructors Constructor Description AnnotationWriter(Writer out)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bfsPrintData(int id, Object... data)
Print a data line.void
bfsPrintHeaders(String... headers)
Print the header line.static AnnotationWriter
create(File file)
Utility method for creating an annotation writer to a file in the native file system.static AnnotationWriter
create(OutputStream out, String filename)
Utility method for creating an annotation writer when you have an output stream.static AnnotationWriter
create(File file)
Utility method for creating an annotation 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
hasPrintedHeaders()
Checks if headers has already been printed or not.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
-
-
-
-
Constructor Detail
-
AnnotationWriter
public AnnotationWriter(Writer out)
-
-
Method Detail
-
create
public static AnnotationWriter create(OutputStream out, String filename)
Utility method for creating an annotation writer when you have an output stream.- Parameters:
out
- The output stream the annotation writer should print tofilename
- Optional, the name of the file the output stream is printing to
-
create
public static AnnotationWriter create(File file)
Utility method for creating an annotation 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 AnnotationWriter create(File file) throws IOException
Utility method for creating an annotation 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.
-
hasPrintedHeaders
public boolean hasPrintedHeaders()
Checks if headers has already been printed or not.
-
getColumnCount
public int getColumnCount()
Get the number of data columns. This information is only available after the headers has been printed.- Returns:
- The number of column, or -1 if the headers has not yet been printed
-
bfsPrintHeaders
public void bfsPrintHeaders(String... headers)
Print the header line. This method must always be called before printing any data. It can only be called once. Each column header must be unique and 'ID' is not allowed since it is always used for the first column. Null values are not allowed.- Parameters:
headers
- The header columns, not including the ID column- Throws:
IllegalStateException
- If headers has already been printedNullPointerException
- If any of the header values is nullIllegalArgumentException
- If a duplicate header is found
-
bfsPrintData
public void bfsPrintData(int id, Object... data)
Print a data line. Before this method can be used headers must have been printed. The size of the data array must be exactly the same as the size of the headers array.- Parameters:
id
- The id of the line, must be a unique positive integerdata
- The data to print- Throws:
IllegalStateException
- If headers has not been printedIllegalArgumentException
- If the ID values is not a unique postive integer or if the size of the data array doesn't match the size of the header arrayNullPointerException
- If the data array is null
-
-