File tree Expand file tree Collapse file tree 2 files changed +27
-16
lines changed
main/java/org/metafacture/io
test/java/org/metafacture/io Expand file tree Collapse file tree 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) {
9090 @ Override
9191 public void process (final T obj ) {
9292 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 );
97104 }
98- else {
99- getWriter (). write ( getSeparator () );
105+ catch ( final IOException e ) {
106+ throw new MetafactureException ( e );
100107 }
101- getWriter ().write (obj .toString ());
102- }
103- catch (final IOException e ) {
104- throw new MetafactureException (e );
105108 }
106109 }
107110
Original file line number Diff line number Diff line change 2020import static org .junit .Assert .assertTrue ;
2121import static org .junit .Assume .assumeFalse ;
2222
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+
2329import java .io .File ;
2430import java .io .FileInputStream ;
2531import java .io .IOException ;
2834import java .nio .charset .StandardCharsets ;
2935import java .nio .file .Files ;
3036
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-
3737/**
3838 * Tests for class {@link ObjectFileWriter}.
3939 *
@@ -105,6 +105,14 @@ public void shouldIncrementCountOnResetBeforeStartingNewFile() throws IOExceptio
105105 assertTrue (new File (tempFolder .getRoot (), "test-1" ).exists ());
106106 }
107107
108+ @ Test
109+ public void issue543_shouldResultEmptyWhenNothingIsProcessed () throws IOException {
110+ writer .process ("" );
111+ writer .closeStream ();
112+
113+ assertOutput ("" );
114+ }
115+
108116 @ Override
109117 protected ConfigurableObjectWriter <String > getWriter () {
110118 return writer ;
You can’t perform that action at this time.
0 commit comments