public class CSVWriter extends Object implements ExportWriter
By default, the patients table is named "patients" + getFileExtension()
and the visits table is named "visits" + getFileExtension(). The EAV
tables are named by their specified ID (also with file extension). The patient and
visit table names can be changed via setPatientTableName(String) and
setVisitTableName(String).
The close() method does nothing, since individual files are written
for each table, which in turn must be closed individually.
TODO maybe allow appending to files
| Constructor and Description |
|---|
CSVWriter(Path directory,
char fieldSeparator,
String fileSuffix)
Create a CSV writer which creates table files
in the specified directory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected String |
escapeData(String data)
Escape data before it is written to the output file.
|
String |
fileNameForTable(String tableName) |
Charset |
getCharset() |
Path |
getDirectory() |
char |
getFieldSeparator() |
String |
getFileExtension() |
String |
getPatientTableName() |
String |
getVisitTableName() |
TableWriter |
openEAVTable(String id) |
TableWriter |
openPatientTable() |
TableWriter |
openVisitTable() |
void |
setFileExtension(String suffix)
Set the file name extension for table files (e.g.
|
void |
setPatientTableName(String tableName) |
void |
setVisitTableName(String tableName) |
public CSVWriter(Path directory, char fieldSeparator, String fileSuffix)
directory - directory where the table files should be created. Must be non-null.fieldSeparator - field separator character.fileSuffix - file name suffix (e.g. .csv)public Charset getCharset()
public Path getDirectory()
public char getFieldSeparator()
public void setFileExtension(String suffix)
.csv).
The extension is appended to table names to produce file names.suffix - file name suffix (usually beginning with a dot)public String getFileExtension()
public void setVisitTableName(String tableName)
public void setPatientTableName(String tableName)
public String getPatientTableName()
public String getVisitTableName()
protected String escapeData(String data)
If the data contains newline characters or field separators, these sequences will be escaped.
data - data fieldpublic TableWriter openPatientTable() throws IOException
openPatientTable in interface ExportWriterIOExceptionpublic TableWriter openVisitTable() throws IOException
openVisitTable in interface ExportWriterIOExceptionpublic TableWriter openEAVTable(String id) throws IOException
openEAVTable in interface ExportWriterIOExceptionpublic void close()
close in interface ExportWriterclose in interface Closeableclose in interface AutoCloseableCopyright © 2013–2017 R.W.Majeed. All rights reserved.