Commit 23de2976 authored by Niels Erik G. Nielsen's avatar Niels Erik G. Nielsen
Browse files

Fix reading of binary MARC input stream for JSON output (RIS-80)

   MarcReader had problems finding record and/or field terminators
   for some records coming in in binary MARC files.

   Seems it was due to one transformation too many. With this commit
   it would no longer make a MARC string of the MARC byte array
   before serving it to MarcToJson.convertMarcRecordsToJson() as a
   ByteArrayInputStream.
parent b43d1388
......@@ -798,7 +798,7 @@ import com.indexdata.masterkey.localindices.util.MarcXMLToJson;
marcJson = MarcXMLToJson.convertMarcXMLToJson(originalContentString);
} else {
logger.log(Level.TRACE,"Treating source record as ISO2079");
marcJson = MarcToJson.convertMarcRecordsToJson(originalContentString).get(0);
marcJson = MarcToJson.convertMarcRecordsToJson(record.getOriginalContent()).get(0);
}
logger.log(Level.TRACE,marcJson.toJSONString());
} catch (IOException | ParserConfigurationException | SAXException e) {
......
......@@ -4,14 +4,10 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.marc4j.*;
import org.marc4j.marc.Record;
import org.xml.sax.SAXException;
......@@ -20,8 +16,7 @@ import org.xml.sax.SAXException;
public class MarcToJson {
public static List<JSONObject> convertMarcRecordsToJson(InputStream inputStream)
throws UnsupportedEncodingException, SAXException, IOException,
ParserConfigurationException {
throws SAXException, IOException, ParserConfigurationException {
List<JSONObject> jsonList = new ArrayList<>();
MarcReader reader = new MarcPermissiveStreamReader(inputStream, true, true);
while(reader.hasNext()) {
......@@ -36,9 +31,9 @@ public class MarcToJson {
return jsonList;
}
public static List<JSONObject> convertMarcRecordsToJson(String marcString)
throws UnsupportedEncodingException, SAXException, IOException, ParserConfigurationException {
return convertMarcRecordsToJson(new ByteArrayInputStream(marcString.getBytes()));
public static List<JSONObject> convertMarcRecordsToJson(byte[] marc)
throws SAXException, IOException, ParserConfigurationException {
return convertMarcRecordsToJson(new ByteArrayInputStream(marc));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment