Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
histream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Raphael
histream
Commits
53a8218a
Commit
53a8218a
authored
Aug 09, 2017
by
R.W.Majeed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
also replace carriage returns in values for CSV exports
parent
71610c3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
2 deletions
+46
-2
histream-export/src/main/java/de/sekmi/histream/export/csv/CSVWriter.java
...src/main/java/de/sekmi/histream/export/csv/CSVWriter.java
+5
-2
histream-export/src/test/java/de/sekmi/histream/export/TestStream.java
...rt/src/test/java/de/sekmi/histream/export/TestStream.java
+41
-0
No files found.
histream-export/src/main/java/de/sekmi/histream/export/csv/CSVWriter.java
View file @
53a8218a
...
...
@@ -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
{
...
...
histream-export/src/test/java/de/sekmi/histream/export/TestStream.java
0 → 100644
View file @
53a8218a
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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment