From d8426fcfc686507cab59b3d8181b08f83718418c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Wed, 14 Mar 2018 10:39:03 +0100 Subject: [PATCH] add line feed control to JSON writer, remove Asciidoclet for now --- build.gradle | 16 +------- gradle.properties | 5 +-- gradle/wrapper/gradle-wrapper.jar | Bin 54333 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 4 +- src/main/java/org/xbib/marc/Marc.java | 1 + src/main/java/org/xbib/marc/MarcRecord.java | 1 + src/main/java/org/xbib/marc/MarcWriter.java | 2 - .../org/xbib/marc/json/MarcJsonWriter.java | 6 ++- .../xbib/marc/json/MarcJsonWriterTest.java | 35 ++++++++++++++++++ .../resources/org/xbib/marc/json/multi.json | 2 + 10 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 src/test/resources/org/xbib/marc/json/multi.json diff --git a/build.gradle b/build.gradle index 22ecd80..e1c5501 100644 --- a/build.gradle +++ b/build.gradle @@ -31,18 +31,16 @@ repositories { } configurations { - asciidoclet wagon } dependencies { + testCompile "org.junit.vintage:junit-vintage-engine:${project.property('junit-vintage.version')}" testCompile "org.xbib:bibliographic-character-sets:${project.property('xbib-bibliographic-character-sets.version')}" testCompile "org.xbib:content-core:${project.property('xbib-content.version')}" - testCompile "junit:junit:${project.property('junit.version')}" testCompile "xalan:xalan:${project.property('xalan.version')}" testCompile "org.xmlunit:xmlunit-matchers:${project.property('xmlunit-matchers.version')}" testCompile "com.github.stefanbirkner:system-rules:${project.property('system-rules.version')}" - asciidoclet "org.xbib:asciidoclet:${project.property('asciidoclet.version')}" wagon "org.apache.maven.wagon:wagon-ssh:${project.property('wagon.version')}" } @@ -78,18 +76,6 @@ asciidoctor { 'source-highlighter': 'coderay' } -javadoc { - options.docletpath = configurations.asciidoclet.files.asType(List) - options.doclet = 'org.xbib.asciidoclet.Asciidoclet' - options.overview = "src/docs/asciidoclet/overview.adoc" - options.addStringOption "-base-dir", "${projectDir}" - options.addStringOption "-attribute", - "name=${project.name},version=${project.version},title-link=https://github.com/xbib/${project.name}" - configure(options) { - noTimestamp = true - } -} - clean { delete 'out' } diff --git a/gradle.properties b/gradle.properties index 053c8b9..cb6ceb9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,11 @@ group = org.xbib name = marc -version = 1.2.0 +version = 1.2.1 xbib-content.version = 1.3.0 xbib-bibliographic-character-sets.version = 1.0.0 xalan.version = 2.7.2 xmlunit-matchers.version = 2.3.0 system-rules.version = 1.16.0 -asciidoclet.version = 1.6.0.0 -junit.version = 4.12 +junit-vintage.version = 4.12.0 wagon.version = 3.0.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index c44b679acd3f794ddbb3aa5e919244914911014a..f6b961fd5a86aa5fbfe90f707c3138408be7c718 100644 GIT binary patch delta 757 zcmY+CUr3Wt7{+&AW7C-VS!CNcr4&o~L{lkNk~%LkW0;eMX_UJtQ_yA@6BN7{7(@fv zcr37JCEXarC;}s-BKOa2&dpgDb!E_vP@r@Z1<~oSzVg7~Jiq6C&dcHDyqe2-IhW%# z=T){xzBg+$8oSS8*KUn$jWCT@em4K>?d}|n&8o}YXqx`Eht~`FMoX|5pBJnCU4kKa zmfgiru#UZkKX{BbH1I|C;%iW$VkTqZw7eqDyDQ&yYg* z^0L-0tK8#zZM)uL{zF5q1h z($xq&6Fp9*qeA+lW}0Xd@@bo%H<6ILB$H$n)`O*d*sKQhE-56pXRStRwF^0BFM$+O z=unTqo*o&49O;6yq78mu+V3OW1t*?xP*#?Ovxd*oyBk@ zTG%DbCb}p%j8DUryqAQJE=kYlon3L4NN$emaBaDc=0~$wiuGlMtm9eK<4Dp>mI*cN zO`fDlw~9ZK9dvL~MdwN@IXo&p^q6pKMZ%7hOc$qA+dsvhm{O?Ir&@uOh5Dye^iOFK zm@ecg2@PqPF5lT!^3G^+BV9|UXSUhvX$vbu>8gW`!M!>}FJ`l4Egpr7P?3@8_H%d^ z%FvgorK<~E)`-!(&&cdLHZ%R~6uQ^0@Xz&Tt={ziFE#v~n>Yude^;dqE&hSu9GWc- delta 705 zcmYL{-%Ha`7{+(rjm?$j*GjXaTd)e{D~3xfrA01^mTOixDlKYW%oMDZpcjQmAYF7} zlSc~EjINT1VkqRYY;&8=`Ey%dMEwKRMHJLc5FJmp&dvEe&-1=7oWmO&)xH_k`u7`q zHjI_nH5$#C{#tj|=k4D+zI8B-p9jW&hx1k|b(&L7Lzb!?I-4(QwjexR_rC*MBModA ztr05=;X$ODeZh5o0X{`kGBbpu`EW6grwIk_D5rCJVVU9A8_+nbz+q4}ijnKbhETMb z9vVf73AM3`wNbH)>;qO}9(D)TnI^JY9IHGZm|eR$6X{y|)@K&nf1U)-PW+ObaS4bPBl>?F&|#=#u!Oi{qn6TsNdFTeQ*PZizkJMIuq~a*@;R zThjWuc#=wb1s=lNq=I`(oHZk`)JB*3WbW_R%JAv zT5x*BL(aiW*f+RVuYi)Ab`4A0o;*M|MckdvyQ`(p@ { /** * Return the MARC fields of this record with a given tag. * + * @param tag the MARC tag * @return the MARC field list matching the given tag. */ public List getFields(String tag) { diff --git a/src/main/java/org/xbib/marc/MarcWriter.java b/src/main/java/org/xbib/marc/MarcWriter.java index 854239f..d6f0166 100644 --- a/src/main/java/org/xbib/marc/MarcWriter.java +++ b/src/main/java/org/xbib/marc/MarcWriter.java @@ -55,7 +55,6 @@ public class MarcWriter extends MarcContentHandler implements Flushable, Closeab * Create a MarcWriter on an underlying output stream. * @param out the underlying output stream * @param charset the character set - * @throws IOException if writer can not be created */ public MarcWriter(OutputStream out, Charset charset) { this(out, charset, DEFAULT_BUFFER_SIZE); @@ -66,7 +65,6 @@ public class MarcWriter extends MarcContentHandler implements Flushable, Closeab * @param out the underlying output stream * @param charset the character set * @param buffersize the buffer size writing to the underlying output stream - * @throws IOException if writer can not be created */ public MarcWriter(OutputStream out, Charset charset, int buffersize) { this.out = new SeparatorOutputStream(out, buffersize); diff --git a/src/main/java/org/xbib/marc/json/MarcJsonWriter.java b/src/main/java/org/xbib/marc/json/MarcJsonWriter.java index a5ffab8..c9e927e 100644 --- a/src/main/java/org/xbib/marc/json/MarcJsonWriter.java +++ b/src/main/java/org/xbib/marc/json/MarcJsonWriter.java @@ -269,7 +269,7 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo sb.append("]"); } if (style == Style.ELASTICSEARCH_BULK) { - // finish with line-feed + // finish with line-feed "\n", not with System.lineSeparator() sb.append("\n"); } try { @@ -435,6 +435,10 @@ public class MarcJsonWriter extends MarcContentHandler implements Flushable, Clo return exception; } + public void writeLine() throws IOException { + writer.write(System.lineSeparator()); + } + private void handleException(IOException e) { exception = e; if (fatalErrors) { diff --git a/src/test/java/org/xbib/marc/json/MarcJsonWriterTest.java b/src/test/java/org/xbib/marc/json/MarcJsonWriterTest.java index c369f71..cb1bebd 100644 --- a/src/test/java/org/xbib/marc/json/MarcJsonWriterTest.java +++ b/src/test/java/org/xbib/marc/json/MarcJsonWriterTest.java @@ -312,4 +312,39 @@ public class MarcJsonWriterTest { assertNull(writer.getException()); } } + + @Test + public void testJsonWriterWithMultipleInput() throws Exception { + File file = File.createTempFile("multi.", ".json"); + file.deleteOnExit(); + FileOutputStream out = new FileOutputStream(file); + try (MarcJsonWriter writer = new MarcJsonWriter(out, MarcJsonWriter.Style.ARRAY)) { + writer.beginCollection(); + try (InputStream inputStream = getClass().getResource("/org/xbib/marc/summerland.mrc").openStream()) { + Marc.builder() + .setFormat(MarcXchangeConstants.MARCXCHANGE_FORMAT) + .setType(MarcXchangeConstants.BIBLIOGRAPHIC_TYPE) + .setInputStream(inputStream) + .setCharset(Charset.forName("ANSEL")) + .setMarcRecordListener(writer) + .build() + .writeRecords(); + } + writer.writeLine(); + try (InputStream inputStream = getClass().getResource("/org/xbib/marc/chabon.mrc").openStream()) { + Marc.builder() + .setFormat(MarcXchangeConstants.MARCXCHANGE_FORMAT) + .setType(MarcXchangeConstants.BIBLIOGRAPHIC_TYPE) + .setInputStream(inputStream) + .setCharset(Charset.forName("ANSEL")) + .setMarcRecordListener(writer) + .build() + .writeRecords(); + } + writer.endCollection(); + } + assertStream("multi", getClass().getResource("/org/xbib/marc/json/multi.json").openStream(), + new FileInputStream(file)); + } + } diff --git a/src/test/resources/org/xbib/marc/json/multi.json b/src/test/resources/org/xbib/marc/json/multi.json new file mode 100644 index 0000000..02a1bfd --- /dev/null +++ b/src/test/resources/org/xbib/marc/json/multi.json @@ -0,0 +1,2 @@ +[{"_FORMAT":"MarcXchange","_TYPE":"Bibliographic","_LEADER":"00714cam a2200205 a 4500","001":["12883376"],"005":["20030616111422.0"],"008":["020805s2002 nyu j 000 1 eng "],"020":[{"__":[{"a":"0786808772"}]},{"__":[{"a":"0786816155 (pbk.)"}]}],"040":[{"__":[{"a":"DLC"},{"c":"DLC"},{"d":"DLC"}]}],"100":[{"1_":[{"a":"Chabon, Michael."}]}],"245":[{"10":[{"a":"Summerland /"},{"c":"Michael Chabon."}]}],"250":[{"__":[{"a":"1st ed."}]}],"260":[{"__":[{"a":"New York :"},{"b":"Miramax Books/Hyperion Books for Children,"},{"c":"c2002."}]}],"300":[{"__":[{"a":"500 p. ;"},{"c":"22 cm."}]}],"520":[{"__":[{"a":"Ethan Feld, the worst baseball player in the history of the game, finds himself recruited by a 100-year-old scout to help a band of fairies triumph over an ancient enemy."}]}],"650":[{"_1":[{"a":"Fantasy."}]},{"_1":[{"a":"Baseball"},{"v":"Fiction."}]},{"_1":[{"a":"Magic"},{"v":"Fiction."}]}]} +,{"_FORMAT":"MarcXchange","_TYPE":"Bibliographic","_LEADER":"00759cam a2200229 a 4500","001":["11939876"],"005":["20041229190604.0"],"008":["000313s2000 nyu 000 1 eng "],"020":[{"__":[{"a":"0679450041 (acid-free paper)"}]}],"040":[{"__":[{"a":"DLC"},{"c":"DLC"},{"d":"DLC"}]}],"100":[{"1_":[{"a":"Chabon, Michael."}]}],"245":[{"14":[{"a":"The amazing adventures of Kavalier and Clay :"},{"b":"a novel /"},{"c":"Michael Chabon."}]}],"260":[{"__":[{"a":"New York :"},{"b":"Random House,"},{"c":"c2000."}]}],"300":[{"__":[{"a":"639 p. ;"},{"c":"25 cm."}]}],"650":[{"_0":[{"a":"Comic books, strips, etc."},{"x":"Authorship"},{"v":"Fiction."}]},{"_0":[{"a":"Heroes in mass media"},{"v":"Fiction."}]},{"_0":[{"a":"Czech Americans"},{"v":"Fiction."}]},{"_0":[{"a":"Young men"},{"v":"Fiction."}]},{"_0":[{"a":"Cartoonists"},{"v":"Fiction."}]}],"651":[{"_0":[{"a":"New York (N.Y.)"},{"v":"Fiction."}]}],"655":[{"_7":[{"a":"Humorous stories."},{"2":"gsafd"}]},{"_7":[{"a":"Bildungsromane."},{"2":"gsafd"}]}]},{"_FORMAT":"MarcXchange","_TYPE":"Bibliographic","_LEADER":"00714cam a2200205 a 4500","001":["12883376"],"005":["20030616111422.0"],"008":["020805s2002 nyu j 000 1 eng "],"020":[{"__":[{"a":"0786808772"}]},{"__":[{"a":"0786816155 (pbk.)"}]}],"040":[{"__":[{"a":"DLC"},{"c":"DLC"},{"d":"DLC"}]}],"100":[{"1_":[{"a":"Chabon, Michael."}]}],"245":[{"10":[{"a":"Summerland /"},{"c":"Michael Chabon."}]}],"250":[{"__":[{"a":"1st ed."}]}],"260":[{"__":[{"a":"New York :"},{"b":"Miramax Books/Hyperion Books for Children,"},{"c":"c2002."}]}],"300":[{"__":[{"a":"500 p. ;"},{"c":"22 cm."}]}],"520":[{"__":[{"a":"Ethan Feld, the worst baseball player in the history of the game, finds himself recruited by a 100-year-old scout to help a band of fairies triumph over an ancient enemy."}]}],"650":[{"_1":[{"a":"Fantasy."}]},{"_1":[{"a":"Baseball"},{"v":"Fiction."}]},{"_1":[{"a":"Magic"},{"v":"Fiction."}]}]}] \ No newline at end of file