File tree 2 files changed +27
-16
lines changed
main/java/org/metafacture/io
test/java/org/metafacture/io
2 files changed +27
-16
lines changed Original file line number Diff line number Diff line change @@ -90,18 +90,21 @@ public void setCompression(final String compression) {
90
90
@ Override
91
91
public void process (final T obj ) {
92
92
assert !closed ;
93
- try {
94
- if (firstObject ) {
95
- getWriter ().write (getHeader ());
96
- firstObject = false ;
93
+ final String objStr = obj .toString ();
94
+ if (!objStr .isEmpty ()) {
95
+ try {
96
+ if (firstObject ) {
97
+ getWriter ().write (getHeader ());
98
+ firstObject = false ;
99
+ }
100
+ else {
101
+ getWriter ().write (getSeparator ());
102
+ }
103
+ getWriter ().write (objStr );
97
104
}
98
- else {
99
- getWriter (). write ( getSeparator () );
105
+ catch ( final IOException e ) {
106
+ throw new MetafactureException ( e );
100
107
}
101
- getWriter ().write (obj .toString ());
102
- }
103
- catch (final IOException e ) {
104
- throw new MetafactureException (e );
105
108
}
106
109
}
107
110
Original file line number Diff line number Diff line change 20
20
import static org .junit .Assert .assertTrue ;
21
21
import static org .junit .Assume .assumeFalse ;
22
22
23
+ import org .junit .Before ;
24
+ import org .junit .Rule ;
25
+ import org .junit .Test ;
26
+ import org .junit .rules .TemporaryFolder ;
27
+ import org .metafacture .commons .ResourceUtil ;
28
+
23
29
import java .io .File ;
24
30
import java .io .FileInputStream ;
25
31
import java .io .IOException ;
28
34
import java .nio .charset .StandardCharsets ;
29
35
import java .nio .file .Files ;
30
36
31
- import org .junit .Before ;
32
- import org .junit .Rule ;
33
- import org .junit .Test ;
34
- import org .junit .rules .TemporaryFolder ;
35
- import org .metafacture .commons .ResourceUtil ;
36
-
37
37
/**
38
38
* Tests for class {@link ObjectFileWriter}.
39
39
*
@@ -105,6 +105,14 @@ public void shouldIncrementCountOnResetBeforeStartingNewFile() throws IOExceptio
105
105
assertTrue (new File (tempFolder .getRoot (), "test-1" ).exists ());
106
106
}
107
107
108
+ @ Test
109
+ public void issue543_shouldResultEmptyWhenNothingIsProcessed () throws IOException {
110
+ writer .process ("" );
111
+ writer .closeStream ();
112
+
113
+ assertOutput ("" );
114
+ }
115
+
108
116
@ Override
109
117
protected ConfigurableObjectWriter <String > getWriter () {
110
118
return writer ;
You can’t perform that action at this time.
0 commit comments