Commit 53a8218a authored by R.W.Majeed's avatar R.W.Majeed
Browse files

also replace carriage returns in values for CSV exports

parent 71610c3a
......@@ -40,7 +40,7 @@ public class CSVWriter implements ExportWriter{
* Create a CSV writer which creates table files
* in the specified directory.
* @param directory directory where the table files should be created. Must be non-null.
* @param fieldSeparator field separator character.
* @param fieldSeparator field separator character. Single space and newline are not allowed as separator characters.
* @param fileSuffix file name suffix (e.g. {@code .csv})
public CSVWriter(Path directory, char fieldSeparator, String fileSuffix){
......@@ -51,6 +51,9 @@ public class CSVWriter implements ExportWriter{
this.filenameExtension = fileSuffix;
this.patientTableName = "patients";
this.visitTableName = "visits";
if( fieldSeparator == ' ' || fieldSeparator == '\n' ){
throw new IllegalArgumentException("Single space and line separator not allowed as field separator");
public Charset getCharset(){
......@@ -101,7 +104,7 @@ public class CSVWriter implements ExportWriter{
protected String escapeData(String data){
// TODO do proper escaping
return data.replace(fieldSeparator, ' ').replace('\n', ' ');
return data.replace(fieldSeparator, ' ').replace('\n', ' ').replace('\r', ' ');
public TableWriter openPatientTable() throws IOException {
package de.sekmi.histream.export;
import java.nio.charset.Charset;
import org.junit.Assert;
import org.junit.Test;
public class TestStream extends OutputStream{
boolean isClosed;
public void write(int arg0) throws IOException {
// do nothing
public void close(){
isClosed = true;
* Verify that the close operation from {@link PrintWriter} will propagate through
* {@link OutputStreamWriter} to the underlying output stream.
public void verifyCascadedClose(){
// no checked exceptions below this point (otherwise must make sure os is closed)
PrintWriter pw = new PrintWriter(new OutputStreamWriter(this, Charset.defaultCharset()));
pw.print("Only for test, will not be written");
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment