[Git][java-team/libmarc4j-java][upstream] New upstream version 2.9.2
Markus Koschany (@apo)
gitlab at salsa.debian.org
Fri Feb 18 23:40:16 GMT 2022
Markus Koschany pushed to branch upstream at Debian Java Maintainers / libmarc4j-java
Commits:
5ebb6a91 by Markus Koschany at 2022-02-19T00:23:45+01:00
New upstream version 2.9.2
- - - - -
15 changed files:
- + .github/workflows/ant.yml
- README.textile
- build.xml
- src/org/marc4j/MarcJsonWriter.java
- src/org/marc4j/MarcPermissiveStreamReader.java
- src/org/marc4j/MarcReaderFactory.java
- src/org/marc4j/MarcStreamWriter.java
- src/org/marc4j/MarcTxtWriter.java
- src/org/marc4j/MarcWriter.java
- + src/org/marc4j/MarcWriterFactory.java
- src/org/marc4j/MarcXmlWriter.java
- src/org/marc4j/Mrk8StreamWriter.java
- src/org/marc4j/converter/impl/UnicodeToUnimarc.java
- src/org/marc4j/util/MarcMerger.java
- src/org/marc4j/util/RecordIODriver.java
Changes:
=====================================
.github/workflows/ant.yml
=====================================
@@ -0,0 +1,24 @@
+# This workflow will build a Java project with Ant
+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-ant
+
+name: Java CI
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout at v2
+ - uses: actions/setup-java at v2
+ with:
+ distribution: 'adopt' # See 'Supported distributions' for available options
+ java-version: '8'
+ java-package: jdk
+ - run: ant -noinput -buildfile build.xml dist test
=====================================
README.textile
=====================================
@@ -1,4 +1,4 @@
-h1. MARC4J !>https://travis-ci.org/marc4j/marc4j.png?branch=master(Build Status)!:https://travis-ci.org/marc4j/marc4j
+h1. MARC4J !>https://github.com/marc4j/marc4j/actions/workflows/ant.yml/badge.svg(Build Status)!:https://github.com/marc4j/marc4j/actions/workflows/ant.yml
h2. Mission
=====================================
build.xml
=====================================
@@ -317,7 +317,7 @@
</jar>
</target>
- <property name="ivy.install.version" value="2.3.0" />
+ <property name="ivy.install.version" value="2.5.0" />
<property name="ivy.jar.dir" value="${basedir}/ivy" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
@@ -329,7 +329,7 @@
<mkdir dir="${ivy.jar.dir}"/>
<echo message="installing ivy..."/>
- <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true"/>
+ <get src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true"/>
</target>
<target name="setup-ivy" depends="download-ivy" description="--> setup ivy" unless="prepared">
=====================================
src/org/marc4j/MarcJsonWriter.java
=====================================
@@ -94,7 +94,11 @@ public class MarcJsonWriter implements MarcWriter {
*/
@Override
public void close() {
- // TODO Auto-generated method stub
+ try {
+ os.close();
+ } catch (IOException e) {
+ throw new MarcException("IO Error occurred closing marc writer", e);
+ }
}
protected String toMarcJson(final Record record) {
@@ -542,4 +546,13 @@ public class MarcJsonWriter implements MarcWriter {
this.normalize = b;
}
+ /**
+ * Whether the writer expects the record passed in to be encoded in Unicode.
+ */
+ @Override
+ public boolean expectsUnicode()
+ {
+ return (converter == null) ? true : false;
+ }
+
}
=====================================
src/org/marc4j/MarcPermissiveStreamReader.java
=====================================
@@ -342,7 +342,16 @@ public class MarcPermissiveStreamReader implements MarcReader, ConverterErrorHan
byte[] recordBuf = new byte[recordLength - 24];
if (permissive) {
input.mark(marc_file_lookahead_buffer);
- input.readFully(recordBuf);
+ try {
+ input.readFully(recordBuf);
+ }
+ catch (final EOFException e) {
+ input.reset();
+ input.mark(marc_file_lookahead_buffer);
+ int toRead = input.available();
+ recordBuf = new byte[toRead];
+ input.readFully(recordBuf);
+ }
if (recordBuf[recordBuf.length - 1] != Constants.RT) {
record.addError("n/a", "n/a", MarcError.MAJOR_ERROR,
"Record terminator character not found at end of record length");
=====================================
src/org/marc4j/MarcReaderFactory.java
=====================================
@@ -77,13 +77,18 @@ public class MarcReaderFactory {
return reader;
}
- public static MarcReader makeReader(MarcReaderConfig config, final InputStream input)
+ public static MarcReader makeReader(MarcReaderConfig config, final String[] searchDirectories, final InputStream input)
throws IOException {
MarcReader reader = makeReaderInternal(config, input);
- reader = decorateMarcReader(reader, config, new String[]{"."});
+ reader = decorateMarcReader(reader, config, searchDirectories);
return(reader);
}
+ public static MarcReader makeReader(MarcReaderConfig config, final InputStream input)
+ throws IOException {
+ return makeReader(config, new String[]{"."}, input);
+ }
+
private static MarcReader makeReaderInternal(MarcReaderConfig config, final InputStream input)
throws IOException {
=====================================
src/org/marc4j/MarcStreamWriter.java
=====================================
@@ -300,4 +300,14 @@ public class MarcStreamWriter implements MarcWriter {
public void setAllowOversizeEntry(final boolean allowOversizeEntry) {
this.allowOversizeEntry = allowOversizeEntry;
}
+
+ /**
+ * Whether the writer expects the record passed in to be encoded in Unicode.
+ */
+ @Override
+ public boolean expectsUnicode()
+ {
+ return (converter != null) ? (converter.outputsUnicode() ? false : true ) : (encoding == "UTF-8" ? true : false);
+ }
+
}
=====================================
src/org/marc4j/MarcTxtWriter.java
=====================================
@@ -124,4 +124,14 @@ public class MarcTxtWriter implements MarcWriter {
this.out.flush();
this.out.close();
}
+
+ /**
+ * Whether the writer expects the record passed in to be encoded in Unicode.
+ */
+ @Override
+ public boolean expectsUnicode()
+ {
+ return (conv == null) ? true : false;
+ }
+
}
\ No newline at end of file
=====================================
src/org/marc4j/MarcWriter.java
=====================================
@@ -59,5 +59,12 @@ public interface MarcWriter {
* Closes the writer.
*/
public void close();
+
+ /**
+ * Whether the writer expects the record passed in to be encoded in Unicode.
+ *
+ * @return boolean whether the writer expects it's input to be encoded in Unicode.
+ */
+ default public boolean expectsUnicode() { return true; }
}
=====================================
src/org/marc4j/MarcWriterFactory.java
=====================================
@@ -0,0 +1,202 @@
+package org.marc4j;
+
+import java.io.OutputStream;
+
+import org.marc4j.converter.impl.UnicodeToAnsel;
+
+public class MarcWriterFactory
+{
+
+// static protected MarcWriter makeWriterFromConvertParm(String convert, boolean pretty, boolean normalize, boolean[] mustBeUtf8, boolean[] marc8Flag, boolean allowOversize, OutputStream out) {
+
+ public static MarcWriter makeWriterFromConvertString(String convertString, OutputStream out)
+ {
+ String convert = "text";
+ boolean pretty = false;
+ boolean normalize = false;
+ boolean oversize = false;
+ int splitAt = 0;
+
+ String[] convertParts = convertString.split("[;:_, ]+");
+ for (String part : convertParts)
+ {
+ if (part.equalsIgnoreCase("text") || part.equalsIgnoreCase("ASCII")) convert = "text";
+ else if (part.equalsIgnoreCase("errors")) convert = "errors";
+ else if (part.equalsIgnoreCase("XML") || part.equalsIgnoreCase("MARCXML")) convert = "xml";
+ else if (part.equalsIgnoreCase("MARC_IN_JSON") || part.equalsIgnoreCase("json")) convert = "json";
+ else if (part.equalsIgnoreCase("MARC_JSON") || part.equalsIgnoreCase("json2")) convert = "json2";
+ else if (part.equalsIgnoreCase("UTF8") || part.equalsIgnoreCase("UTF-8")) convert = "utf8";
+ else if (part.equalsIgnoreCase("RAW") || part.equalsIgnoreCase("raw")) convert = "raw";
+ else if (part.equalsIgnoreCase("MARC8")) convert = "marc8";
+ else if (part.equalsIgnoreCase("MARC8NCR") || part.equalsIgnoreCase("NCR")) convert = "marc8ncr";
+ else if (part.equalsIgnoreCase("MRK8") || part.equalsIgnoreCase("MARCEDIT")) convert = "mrk8";
+ else if (part.matches("([0-9][0-9][0-9]|err)(:([0-9][0-9][0-9]|err))*")) convert = part;
+
+ else if (part.equalsIgnoreCase("pretty") || part.equalsIgnoreCase("indent") ) pretty = true;
+ else if (part.equalsIgnoreCase("normalize") || part.equalsIgnoreCase("normalized") ) normalize = true;
+ else if (part.startsWith("split"))
+ {
+ splitAt = 70000;
+ }
+ else if (part.equalsIgnoreCase("oversize"))
+ {
+ oversize = true;
+ }
+ }
+ return makeWriterFromConvertParm(convert, pretty, normalize, oversize, splitAt, out );
+ }
+
+ public static MarcWriter makeWriterFromConvertParm(String convert, boolean pretty, boolean normalize, boolean oversize, int splitAt, OutputStream out)
+ {
+ MarcWriter writer = null;
+
+ if (convert.equalsIgnoreCase("text") || convert.equalsIgnoreCase("ASCII"))
+ {
+ writer = new MarcTxtWriter(out);
+ }
+ else if (convert.equalsIgnoreCase("errors"))
+ {
+ writer = new MarcTxtWriter(out, "001;err");
+ }
+ else if (convert.matches("([0-9][0-9][0-9]|err)(:([0-9][0-9][0-9]|err))*"))
+ {
+ writer = new MarcTxtWriter(out, convert);
+ }
+ else if (convert.equalsIgnoreCase("XML") || convert.equalsIgnoreCase("MARCXML"))
+ {
+ MarcXmlWriter xmlwriter = new MarcXmlWriter(out, "UTF8");
+ if (pretty) xmlwriter.setIndent(true);
+ if (normalize) xmlwriter.setUnicodeNormalization(true);
+ writer = xmlwriter;
+ }
+ else if (convert.equalsIgnoreCase("MARC_IN_JSON") || convert.equalsIgnoreCase("json"))
+ {
+ MarcJsonWriter jsonwriter = new MarcJsonWriter(out, MarcJsonWriter.MARC_IN_JSON);
+ if (pretty) jsonwriter.setIndent(true);
+ if (normalize) jsonwriter.setUnicodeNormalization(true);
+ writer = jsonwriter;
+ }
+ else if (convert.equalsIgnoreCase("MARC_JSON") || convert.equalsIgnoreCase("json2"))
+ {
+ MarcJsonWriter jsonwriter = new MarcJsonWriter(out, MarcJsonWriter.MARC_JSON);
+ if (pretty) jsonwriter.setIndent(true);
+ if (normalize) jsonwriter.setUnicodeNormalization(true);
+ writer = jsonwriter;
+ }
+ else if (convert.equalsIgnoreCase("UTF8") || convert.equalsIgnoreCase("UTF-8"))
+ {
+ MarcStreamWriter binwriter;
+ if (splitAt == 0)
+ {
+ binwriter = new MarcStreamWriter(out, "UTF8", true);
+ binwriter.setAllowOversizeEntry(oversize);
+ }
+ else
+ {
+ binwriter = new MarcSplitStreamWriter(out, splitAt, "UTF8");
+ }
+ writer = binwriter;
+ }
+ else if (convert.equalsIgnoreCase("raw") )
+ {
+ MarcStreamWriter binwriter;
+ if (splitAt == 0)
+ {
+ binwriter = new MarcStreamWriter(out, "per_record", true);
+ binwriter.setAllowOversizeEntry(oversize);
+ }
+ else
+ {
+ binwriter = new MarcSplitStreamWriter(out, splitAt, "UTF8");
+ }
+ writer = binwriter;
+ }
+ else if (convert.equalsIgnoreCase("MARC8") || convert.equalsIgnoreCase("MARC8NCR") || convert.equalsIgnoreCase("NCR"))
+ {
+ MarcStreamWriter binwriter;
+ if (splitAt == 0)
+ {
+ binwriter = new MarcStreamWriter(out, "ISO8859_1", true);
+ binwriter.setAllowOversizeEntry(oversize);
+ }
+ else
+ {
+ binwriter = new MarcSplitStreamWriter(out, splitAt, "ISO8859_1");
+ }
+ binwriter.setConverter(new UnicodeToAnsel(convert.contains("NCR")));
+ writer = binwriter;
+ }
+ else if (convert.equalsIgnoreCase("MRK8"))
+ {
+ Mrk8StreamWriter mrkwriter = new Mrk8StreamWriter(out);
+ writer = mrkwriter;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Error : Unknown output format: "+ convert );
+ }
+ return(writer);
+ }
+
+// public static MarcWriter makeWriterFromConvertParm(String convert, boolean pretty, boolean normalize, boolean[] mustBeUtf8, boolean[] marc8Flag, boolean allowOversize, OutputStream out) {
+// MarcWriter writer = null;
+//
+// if (convert.equalsIgnoreCase("text") || convert.equalsIgnoreCase("ASCII")) {
+// writer = new MarcTxtWriter(out);
+// } else if (convert.equalsIgnoreCase("errors")) {
+// writer = new MarcTxtWriter(out, "001;err");
+// } else if (convert.matches("([0-9][0-9][0-9]|err)(:([0-9][0-9][0-9]|err))*")) {
+// writer = new MarcTxtWriter(out, convert);
+// } else if (convert.equalsIgnoreCase("XML") || convert.equalsIgnoreCase("MARCXML")) {
+// mustBeUtf8[0] = true;
+// MarcXmlWriter xmlwriter = new MarcXmlWriter(out, "UTF8");
+// if (pretty) xmlwriter.setIndent(true);
+// if (normalize) xmlwriter.setUnicodeNormalization(true);
+// writer = xmlwriter;
+// } else if (convert.equalsIgnoreCase("MARC_IN_JSON") || convert.equalsIgnoreCase("json")) {
+// mustBeUtf8[0] = true;
+// MarcJsonWriter jsonwriter = new MarcJsonWriter(out, MarcJsonWriter.MARC_IN_JSON);
+// if (pretty) jsonwriter.setIndent(true);
+// if (normalize) jsonwriter.setUnicodeNormalization(true);
+// writer = jsonwriter;
+// } else if (convert.equalsIgnoreCase("MARC_JSON") || convert.equalsIgnoreCase("json2")) {
+// mustBeUtf8[0] = true;
+// MarcJsonWriter jsonwriter = new MarcJsonWriter(out, MarcJsonWriter.MARC_JSON);
+// if (pretty) jsonwriter.setIndent(true);
+// if (normalize) jsonwriter.setUnicodeNormalization(true);
+// writer = jsonwriter;
+// } else if (convert.equalsIgnoreCase("UTF8") || convert.equalsIgnoreCase("UTF-8")) {
+// mustBeUtf8[0] = true;
+// MarcStreamWriter binwriter = new MarcStreamWriter(out, "UTF8");
+// if (allowOversize) {
+// binwriter.setAllowOversizeEntry(true);
+// }
+// writer = binwriter;
+// } else if (convert.equalsIgnoreCase("MARC8")) {
+// MarcStreamWriter binwriter = new MarcStreamWriter(out, "ISO8859_1", true);
+// binwriter.setConverter(new UnicodeToAnsel());
+// marc8Flag[0] = true;
+// if (allowOversize) {
+// binwriter.setAllowOversizeEntry(true);
+// }
+// writer = binwriter;
+// } else if (convert.equalsIgnoreCase("MARC8NCR") || convert.equalsIgnoreCase("NCR")) {
+// MarcStreamWriter binwriter = new MarcStreamWriter(out, "ISO8859_1", true);
+// binwriter.setConverter(new UnicodeToAnsel(true));
+// marc8Flag[0] = true;
+// if (allowOversize) {
+// binwriter.setAllowOversizeEntry(true);
+// }
+// writer = binwriter;
+// } else if (convert.equalsIgnoreCase("MRK8")) {
+// mustBeUtf8[0] = true;
+// Mrk8StreamWriter mrkwriter = new Mrk8StreamWriter(out);
+// writer = mrkwriter;
+// } else {
+// throw new IllegalArgumentException("Error : Unknown output format: "+ convert );
+//// System.exit(1);
+// }
+// return(writer);
+// }
+
+}
=====================================
src/org/marc4j/MarcXmlWriter.java
=====================================
@@ -710,4 +710,13 @@ public class MarcXmlWriter implements MarcWriter {
return false;
}
+
+ /**
+ * Whether the writer expects the record passed in to be encoded in Unicode.
+ */
+ @Override
+ public boolean expectsUnicode()
+ {
+ return (converter == null) ? true : false;
+ }
}
=====================================
src/org/marc4j/Mrk8StreamWriter.java
=====================================
@@ -152,4 +152,14 @@ public class Mrk8StreamWriter implements MarcWriter {
this.mrk8Writer.flush();
this.mrk8Writer.close();
}
+
+ /**
+ * Whether the writer expects the record passed in to be encoded in Unicode.
+ */
+ @Override
+ public boolean expectsUnicode()
+ {
+ return true;
+ }
+
}
=====================================
src/org/marc4j/converter/impl/UnicodeToUnimarc.java
=====================================
@@ -74,9 +74,9 @@ public class UnicodeToUnimarc extends CharConverter implements UnimarcConstants
try {
final Class<?> generated = Class.forName("org.marc4j.converter.impl.UnimarcReverseCodeTableGenerated");
final Constructor<?> cons = generated.getConstructor();
- final Object rct = cons.newInstance();
+ final Object localRct = cons.newInstance();
- return (UnimarcReverseCodeTableHash) rct;
+ return (ReverseCodeTable) localRct;
} catch (final Exception e) {
return new UnimarcReverseCodeTableHash(getClass().getResourceAsStream("resources/unimarc.xml"));
}
=====================================
src/org/marc4j/util/MarcMerger.java
=====================================
@@ -42,33 +42,48 @@ public class MarcMerger
String newRecordsOut = null;
int argoffset = 0;
boolean mergeRecords = true;
- if (args[0].equals("-v"))
+ String modfile = null;
+ String delfile = null;
+ while (argoffset < args.length && args[argoffset].startsWith("-"))
{
- verbose = true;
- argoffset = 1;
- }
- if (args[0].equals("-vv"))
- {
- verbose = true;
- veryverbose = true;
- argoffset = 1;
- }
- if (args[0+argoffset].equals("-min"))
- {
- segmentMinRecordID = args[1+argoffset];
- argoffset += 2;
- }
- if (args[0+argoffset].equals("-max"))
- {
- segmentMaxRecordID = args[1+argoffset];
- argoffset += 2;
- }
- if (args[0+argoffset].equals("-new"))
- {
- newRecordsOut = args[1+argoffset];
- argoffset += 2;
+ if (args[0+argoffset].equals("-v"))
+ {
+ verbose = true;
+ argoffset = 1;
+ }
+ if (args[0+argoffset].equals("-vv"))
+ {
+ verbose = true;
+ veryverbose = true;
+ argoffset = 1;
+ }
+ if (args[0+argoffset].equals("-min"))
+ {
+ segmentMinRecordID = args[1+argoffset];
+ argoffset += 2;
+ }
+ if (args[0+argoffset].equals("-max"))
+ {
+ segmentMaxRecordID = args[1+argoffset];
+ argoffset += 2;
+ }
+ if (args[0+argoffset].equals("-new"))
+ {
+ newRecordsOut = args[1+argoffset];
+ argoffset += 2;
+ }
+ if (args[0+argoffset].equals("-mrc"))
+ {
+ modfile = args[1+argoffset];
+ argoffset += 2;
+ }
+ if (args[0+argoffset].equals("-del"))
+ {
+ delfile = args[1+argoffset];
+ argoffset += 2;
+ }
}
- if (args[0+argoffset].endsWith(".del"))
+ if (args[0+argoffset].endsWith(".del") || args[0+argoffset].endsWith(".ids"))
{
// merging deletes, not merging records.
mergeRecords = false;
@@ -97,16 +112,18 @@ public class MarcMerger
}
try
{
- String modfile = args[1+argoffset];
- String delfile = null;
boolean use_stdin = false;
FileOutputStream newRecordsOutStream = null;
+ if (modfile == null)
+ {
+ modfile = args[1+argoffset];
+ }
if (modfile.equals ("-"))
{
use_stdin = true;
}
- else if (modfile.endsWith(".mrc") )
+ else if (modfile.endsWith(".mrc") && delfile == null)
{
delfile = modfile.substring(0, modfile.length()-4) + ".del";
}
@@ -321,25 +338,17 @@ public class MarcMerger
}
else // mainrec.id is greater than either newOrModrec.id or deletedId
{
- if (newOrModrec != null && compare.compare(mainDelete, newOrModrec.getRecordId())> 0 && compare.compare(newOrModrec.getRecordId(), deletedId)== 0)
+ if (newOrModrec != null && compare.compare(mainDelete, newOrModrec.getRecordId())> 0)
{
- // Update contains a new
- out.println(mainDelete);
+ // newOrModrec is a new record, Write out new record.
+ if (verbose) System.err.println("New record in mod file "+ newOrModrec.getRecordId() + " skipping it.");
+ newOrModrec = newOrModified.hasNext() ? newOrModified.next() : null;
}
- else
- {
- if (newOrModrec != null && compare.compare(mainDelete, newOrModrec.getRecordId())> 0)
- {
- // newOrModrec is a new record, Write out new record.
- if (verbose) System.err.println("New record in mod file "+ newOrModrec.getRecordId() + " skipping it.");
- newOrModrec = newOrModified.hasNext() ? newOrModified.next() : null;
- }
- if (compare.compare(mainDelete, deletedId)> 0)
- {
- // Trying to delete a record that's already not there. Be Happy.
- out.println(deletedId);
- deletedId = getNextDelId(delReader);
- }
+ if (compare.compare(mainDelete, deletedId)> 0)
+ {
+ // Trying to delete a record that's already not there. Be Happy.
+ out.println(deletedId);
+ deletedId = getNextDelId(delReader);
}
}
}
=====================================
src/org/marc4j/util/RecordIODriver.java
=====================================
@@ -17,6 +17,7 @@ import org.marc4j.MarcReaderFactory;
import org.marc4j.MarcStreamWriter;
import org.marc4j.MarcTxtWriter;
import org.marc4j.MarcWriter;
+import org.marc4j.MarcWriterFactory;
import org.marc4j.MarcXmlWriter;
import org.marc4j.Mrk8StreamWriter;
import org.marc4j.converter.impl.UnicodeToAnsel;
@@ -29,7 +30,8 @@ public class RecordIODriver {
String convert;
boolean normalize = false;
boolean pretty = true;
- boolean marc8Flag = false;
+ boolean oversize = false;
+ int splitAt = 0;
boolean writeErrorRecs = true;
boolean writeNoErrorRecs = true;
List<String>otherArgs = new ArrayList<String>();
@@ -66,11 +68,6 @@ public class RecordIODriver {
return pretty;
}
- public boolean isMarc8()
- {
- return marc8Flag;
- }
-
public boolean shouldWriteErrorRecs()
{
return writeErrorRecs;
@@ -164,7 +161,6 @@ public class RecordIODriver {
final Record record = reader.next();
location = "in";
controlNumber = record.getControlNumber();
- record.getLeader().setCharCodingScheme((driverInfo.marc8Flag ? ' ' : 'a'));
if ((driverInfo.writeErrorRecs && driverInfo.writeNoErrorRecs) ||
(driverInfo.writeErrorRecs && record.hasErrors()) ||
(driverInfo.writeNoErrorRecs && !record.hasErrors())) {
@@ -240,6 +236,10 @@ public class RecordIODriver {
encoding = args[++i].trim();
} else if (args[i].equals("-pretty")) {
driverInfo.pretty = true;
+ } else if (args[i].equals("-split")) {
+ driverInfo.splitAt = 70000;
+ } else if (args[i].equals("-oversize")) {
+ driverInfo.oversize = true;
} else if (args[i].equals("-normalize")) {
driverInfo.normalize = true;
} else if (args[i].equals("-strict")) {
@@ -283,71 +283,14 @@ public class RecordIODriver {
}
static protected MarcWriter makeWriterFromConvertParm(RecordIODriver driverInfo, OutputStream out) {
- MarcWriter writer = null;
- boolean mustBeUtf8 = false;
+ MarcWriter result = MarcWriterFactory.makeWriterFromConvertParm(driverInfo.convert, driverInfo.pretty, driverInfo.normalize, driverInfo.oversize, driverInfo.splitAt, out);
- if (driverInfo.convert.equalsIgnoreCase("text") || driverInfo.convert.equalsIgnoreCase("ASCII")) {
- writer = new MarcTxtWriter(out);
- } else if (driverInfo.convert.equalsIgnoreCase("errors")) {
- writer = new MarcTxtWriter(out, "001;err");
- } else if (driverInfo.convert.matches("([0-9][0-9][0-9]|err)(:([0-9][0-9][0-9]|err))*")) {
- writer = new MarcTxtWriter(out, driverInfo.convert);
- } else if (driverInfo.convert.equalsIgnoreCase("XML") || driverInfo.convert.equalsIgnoreCase("MARCXML")) {
- mustBeUtf8 = true;
- MarcXmlWriter xmlwriter = new MarcXmlWriter(out, "UTF8");
- if (driverInfo.pretty) xmlwriter.setIndent(true);
- if (driverInfo.normalize) xmlwriter.setUnicodeNormalization(true);
- writer = xmlwriter;
- } else if (driverInfo.convert.equalsIgnoreCase("MARC_IN_JSON") || driverInfo.convert.equalsIgnoreCase("json")) {
- mustBeUtf8 = true;
- MarcJsonWriter jsonwriter = new MarcJsonWriter(out, MarcJsonWriter.MARC_IN_JSON);
- if (driverInfo.pretty) jsonwriter.setIndent(true);
- if (driverInfo.normalize) jsonwriter.setUnicodeNormalization(true);
- writer = jsonwriter;
- } else if (driverInfo.convert.equalsIgnoreCase("MARC_JSON") || driverInfo.convert.equalsIgnoreCase("json2")) {
- mustBeUtf8 = true;
- MarcJsonWriter jsonwriter = new MarcJsonWriter(out, MarcJsonWriter.MARC_JSON);
- if (driverInfo.pretty) jsonwriter.setIndent(true);
- if (driverInfo.normalize) jsonwriter.setUnicodeNormalization(true);
- writer = jsonwriter;
- } else if (driverInfo.convert.equalsIgnoreCase("UTF8") || driverInfo.convert.equalsIgnoreCase("UTF-8")) {
- mustBeUtf8 = true;
- MarcStreamWriter binwriter = new MarcStreamWriter(out, "UTF8");
- if (driverInfo.readerConfig.getCombineConsecutiveRecordsFields() != null) {
- binwriter.setAllowOversizeEntry(true);
- }
- writer = binwriter;
- } else if (driverInfo.convert.equalsIgnoreCase("MARC8")) {
- MarcStreamWriter binwriter = new MarcStreamWriter(out, "ISO8859_1", true);
- binwriter.setConverter(new UnicodeToAnsel());
- driverInfo.marc8Flag = true;
- if (driverInfo.readerConfig.getCombineConsecutiveRecordsFields() != null) {
- binwriter.setAllowOversizeEntry(true);
- }
- writer = binwriter;
- } else if (driverInfo.convert.equalsIgnoreCase("MARC8NCR") || driverInfo.convert.equalsIgnoreCase("NCR")) {
- MarcStreamWriter binwriter = new MarcStreamWriter(out, "ISO8859_1", true);
- binwriter.setConverter(new UnicodeToAnsel(true));
- driverInfo.marc8Flag = true;
- if (driverInfo.readerConfig.getCombineConsecutiveRecordsFields() != null) {
- binwriter.setAllowOversizeEntry(true);
- }
- writer = binwriter;
- } else if (driverInfo.convert.equalsIgnoreCase("MRK8")) {
- mustBeUtf8 = true;
- Mrk8StreamWriter mrkwriter = new Mrk8StreamWriter(out);
- writer = mrkwriter;
- } else {
- throw new IllegalArgumentException("Error : Unknown output format: "+ driverInfo.convert );
-// System.exit(1);
- }
- if (mustBeUtf8 && driverInfo.readerConfig.toUtf8() == false) {
+ if (result.expectsUnicode() && driverInfo.readerConfig.toUtf8() == false) {
driverInfo.readerConfig.setToUtf8(true);
}
- return(writer);
+ return(result);
}
-
private static void usage(String error, int exitcode) {
if (error != null) {
System.err.println("Error: "+ error);
View it on GitLab: https://salsa.debian.org/java-team/libmarc4j-java/-/commit/5ebb6a916070d93099d9aaefee3011f2df6bc5b1
--
View it on GitLab: https://salsa.debian.org/java-team/libmarc4j-java/-/commit/5ebb6a916070d93099d9aaefee3011f2df6bc5b1
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20220218/5c561fbe/attachment.htm>
More information about the pkg-java-commits
mailing list