Skip to content

Commit 7b6e932

Browse files
committed
Merge remote-tracking branch 'origin/master' into 495-objectSleep
2 parents 489a74d + bdb93ad commit 7b6e932

File tree

6 files changed

+63
-20
lines changed

6 files changed

+63
-20
lines changed

gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=1541fa36599e12857140465f3c91a97409b4512501c26f9631fb113e392c5bd1
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
3+
distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
55
networkTimeout=10000
66
validateDistributionUrl=true
77
zipStoreBase=GRADLE_USER_HOME

metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void literal(final String name, final String value) {
212212

213213
@Override
214214
protected void onResetStream() {
215-
pipe.resetStream();
215+
encoder.onResetStream();
216216
}
217217

218218
@Override
@@ -372,7 +372,9 @@ protected void onResetStream() {
372372

373373
@Override
374374
protected void onCloseStream() {
375-
writeFooter();
375+
if (!atStreamStart) {
376+
writeFooter();
377+
}
376378
sendAndClearData();
377379
}
378380

metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class MarcXmlEncoderTest {
5151
private static final String RECORD_ID = "92005291";
5252

5353
private static StringBuilder resultCollector;
54+
private static int resultCollectorsResetStreamCount;
5455
private static MarcXmlEncoder encoder;
5556

5657
@Before
@@ -62,6 +63,11 @@ public void setUp() {
6263
public void process(final String obj) {
6364
resultCollector.append(obj);
6465
}
66+
@Override
67+
public void resetStream() {
68+
++resultCollectorsResetStreamCount;
69+
}
70+
6571
});
6672
resultCollector = new StringBuilder();
6773
}
@@ -389,4 +395,26 @@ public void shouldNotEncodeNestedTypeLiteralAsAttribute() {
389395
assertEquals(expected, actual);
390396
}
391397

398+
@Test
399+
public void issue543_shouldNotWriteFooterWhenRecordIsEmpty() {
400+
encoder.closeStream();
401+
String actual = resultCollector.toString();
402+
assertTrue(actual.isEmpty());
403+
}
404+
405+
@Test
406+
public void issue543_shouldOnlyResetStreamOnce() {
407+
resultCollectorsResetStreamCount = 0;
408+
encoder.resetStream();
409+
assertEquals(resultCollectorsResetStreamCount, 1);
410+
}
411+
412+
@Test
413+
public void issue543_shouldOnlyResetStreamOnceUsingWrapper() {
414+
resultCollectorsResetStreamCount = 0;
415+
encoder.setEnsureCorrectMarc21Xml(true);
416+
encoder.resetStream();
417+
assertEquals(resultCollectorsResetStreamCount, 1);
418+
}
419+
392420
}

metafacture-io/src/main/java/org/metafacture/io/ObjectFileWriter.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff 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

metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
import static org.junit.Assert.assertTrue;
2121
import 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+
2329
import java.io.File;
2430
import java.io.FileInputStream;
2531
import java.io.IOException;
@@ -28,12 +34,6 @@
2834
import java.nio.charset.StandardCharsets;
2935
import 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;

metafacture-mangling/src/main/java/org/metafacture/mangling/ObjectToLiteral.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.metafacture.framework.FluxCommand;
2020
import org.metafacture.framework.StreamReceiver;
2121
import org.metafacture.framework.annotations.Description;
22+
import org.metafacture.framework.annotations.In;
2223
import org.metafacture.framework.annotations.Out;
2324
import org.metafacture.framework.helpers.DefaultObjectPipe;
2425

@@ -29,6 +30,7 @@
2930
* @author Christoph Böhme, Fabian Steeg
3031
*/
3132
@Description("Outputs a record containing the input object as literal")
33+
@In(Object.class)
3234
@Out(StreamReceiver.class)
3335
@FluxCommand("object-to-literal")
3436
public final class ObjectToLiteral<T> extends

0 commit comments

Comments
 (0)