Loading histream-export/src/main/java/de/sekmi/histream/export/csv/CSVWriter.java +5 −2 Original line number Diff line number Diff line Loading @@ -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){ Loading @@ -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(){ Loading Loading @@ -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 { Loading histream-export/src/test/java/de/sekmi/histream/export/TestStream.java 0 → 100644 +41 −0 Original line number Diff line number Diff line 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); } } Loading
histream-export/src/main/java/de/sekmi/histream/export/csv/CSVWriter.java +5 −2 Original line number Diff line number Diff line Loading @@ -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){ Loading @@ -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(){ Loading Loading @@ -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 { Loading
histream-export/src/test/java/de/sekmi/histream/export/TestStream.java 0 → 100644 +41 −0 Original line number Diff line number Diff line 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); } }