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

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', ' ');
}
@Override
public TableWriter openPatientTable() throws IOException {
......
package de.sekmi.histream.export;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import org.junit.Assert;
import org.junit.Test;
public class TestStream extends OutputStream{
boolean isClosed;
@Override
public void write(int arg0) throws IOException {
// do nothing
}
@Override
public void close(){
isClosed = true;
}
/**
* Verify that the close operation from {@link PrintWriter} will propagate through
* {@link OutputStreamWriter} to the underlying output stream.
*/
@Test
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.println();
pw.print("Only for test, will not be written");
pw.flush();
pw.close();
Assert.assertTrue(isClosed);
}
}
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