• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java MarcWriter类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.marc4j.MarcWriter的典型用法代码示例。如果您正苦于以下问题:Java MarcWriter类的具体用法?Java MarcWriter怎么用?Java MarcWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

MarcWriter类属于org.marc4j包,在下文中一共展示了MarcWriter类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: readMARCRecords

点赞 3

import org.marc4j.MarcWriter; //导入依赖的package包/类
private Sequence readMARCRecords(final MarcReader aReader) throws XPathException {
    final MemTreeBuilder builder = context.getDocumentBuilder();
    final DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);
    final SAXResult saxResult = new SAXResult(receiver);
    final MarcWriter writer = new MarcXmlWriter(saxResult);

    writer.setConverter(new AnselToUnicode());

    while (aReader.hasNext()) {
        final Record record = aReader.next();
        final String recordId = record.getControlNumber();

        if (LOGGER.isDebugEnabled() && recordId != null) {
            LOGGER.debug("Reading MARC record: " + recordId);
        }

        writer.write(record);
    }

    writer.close();

    return (DocumentImpl) receiver.getDocument();
}
 

开发者ID:ksclarke,
项目名称:freelib-marc4j-exist,
代码行数:24,
代码来源:ReadFromFile.java

示例2: createMarcRecord

点赞 3

import org.marc4j.MarcWriter; //导入依赖的package包/类
public void createMarcRecord(String marcRecordContent, String filePath) throws Exception {
    File fileToWrite = new File(filePath);
    FileOutputStream fileOutputStream = new FileOutputStream(fileToWrite);
    //String bibContent = StringUtils.join(bibDocList, "");
    InputStream input = new ByteArrayInputStream(marcRecordContent.getBytes());
    if (!fileToWrite.exists()) {
        fileToWrite.getParentFile().mkdirs();
        fileToWrite.createNewFile();
    }
    try {
        MarcXmlReader marcXmlReader = new MarcXmlReader(input);
        MarcWriter writer = new MarcStreamWriter(fileOutputStream);

        while (marcXmlReader.hasNext()) {
            Record record = marcXmlReader.next();
            writer.write(record);
        }
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 

开发者ID:VU-libtech,
项目名称:OLE-INST,
代码行数:24,
代码来源:OLEBatchProcessDataHelper.java

示例3: convertRawMarcToXML

点赞 2

import org.marc4j.MarcWriter; //导入依赖的package包/类
/**
 * @param inputFile
 * @return converted marc xml File Name
 * @throws java.io.FileNotFoundException This method takes in a raw marc file and converts into a marc xml file.
 */
public String convertRawMarcToXML(File inputFile) throws FileNotFoundException {
    InputStream input = new FileInputStream(inputFile);
    String fileName = inputFile.getName().replace(".mrc", ".xml");
    FileOutputStream fileOutputStream = new FileOutputStream(new File(fileName));
    MarcReader reader = new MarcStreamReader(input);
    MarcWriter writer = new MarcXmlWriter(fileOutputStream, true);

    while (reader.hasNext()) {
        Record record = reader.next();
        writer.write(record);
    }
    writer.close();
    return fileName;
}
 

开发者ID:VU-libtech,
项目名称:OLE-INST,
代码行数:20,
代码来源:MarcXMLConverter.java

示例4: convert

点赞 2

import org.marc4j.MarcWriter; //导入依赖的package包/类
/**
 * @param content
 * @return converted marc xml
 */
public String convert(String content) {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content.getBytes());
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    MarcReader reader = new MarcStreamReader(byteArrayInputStream);
    MarcWriter writer = new MarcXmlWriter(byteArrayOutputStream, true);

    while (reader.hasNext()) {
        Record record = reader.next();
        writer.write(record);
    }
    writer.close();
    return new String(byteArrayOutputStream.toByteArray());
}
 

开发者ID:VU-libtech,
项目名称:OLE-INST,
代码行数:19,
代码来源:MarcXMLConverter.java

示例5: convert

点赞 2

import org.marc4j.MarcWriter; //导入依赖的package包/类
public String convert(String content) {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content.getBytes());
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    MarcWriter writer = new MarcXmlWriter(byteArrayOutputStream, true);


    Record record;
    String inline;

    BufferedReader br = null;
    br = new BufferedReader(new InputStreamReader(byteArrayInputStream));
    record = marcFactory.newRecord();

    try {
        while ((inline = br.readLine()) != null) {

            if (inline.equals("") || inline.startsWith(" ")) {
                writer.write(record);
                record = marcFactory.newRecord();
            } else {
                record = addLineToRecord(inline, record);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    writer.write(record);
    writer.close();
    return new String(byteArrayOutputStream.toByteArray());

}
 

开发者ID:VU-libtech,
项目名称:OLE-INST,
代码行数:33,
代码来源:MRKToMARCXMLConverter.java

示例6: convert

点赞 2

import org.marc4j.MarcWriter; //导入依赖的package包/类
public String convert(String content) {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content.getBytes());
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    MarcWriter writer = new MarcXmlWriter(byteArrayOutputStream, true);

    Record record;
    String inline;

    BufferedReader br = null;
    br = new BufferedReader(new InputStreamReader(byteArrayInputStream));
    record = marcFactory.newRecord();

    try {
        while ((inline = br.readLine()) != null) {
            if (inline.equals("") || inline.startsWith(" ")) {
                writer.write(record);
                record = marcFactory.newRecord();
            } else {
                record = addLineToRecord(inline, record);
            }
        }
    } catch (IOException e) {

    }

    writer.write(record);
    writer.close();
    return new String(byteArrayOutputStream.toByteArray());

}
 

开发者ID:VU-libtech,
项目名称:OLE-INST,
代码行数:31,
代码来源:MRKToMARCXMLConverter.java

示例7: generateMarcFromXml

点赞 2

import org.marc4j.MarcWriter; //导入依赖的package包/类
public void generateMarcFromXml(String fileName, String filePath, List<String> bibMarcRecordList) {
    StopWatch timer = new StopWatch();
    timer.start();
    File fileToWrite = new File(filePath + FileSystems.getDefault().getSeparator() + fileName + ".mrc");
    FileOutputStream fileOutputStream = null;
    try {
        fileOutputStream = new FileOutputStream(fileToWrite, true);
    } catch (FileNotFoundException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }
    MarcWriter writer = new MarcStreamWriter(fileOutputStream, "UTF-8");
    for (String bibContent : bibMarcRecordList) {
        InputStream input = new ByteArrayInputStream(bibContent.getBytes());
        Record record = null;
        try {
            OLEMarcReader marcXmlReader = new OLEMarcXmlReader(input);
            while (marcXmlReader.hasNext()) {
                if (marcXmlReader.hasErrors()) {
                    marcXmlReader.next();
                    marcXmlReader.clearErrors();
                    continue;
                }
                record = marcXmlReader.next();
                writer.write(record);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    writer.close();
    timer.stop();
}
 

开发者ID:VU-libtech,
项目名称:OLE-INST,
代码行数:34,
代码来源:BatchProcessImport_UT.java

示例8: generateMarcFromXml

点赞 2

import org.marc4j.MarcWriter; //导入依赖的package包/类
/**
 * Writes the content read into a mrc file
 *
 * @param bibMarcRecords
 * @param batchExportStatistics
 * @param isFirstBatch
 * @param isLastBatch
 * @throws Exception
 */
public int generateMarcFromXml(List<BibMarcRecord> bibMarcRecords, BatchExportStatistics batchExportStatistics, Boolean isFirstBatch, Boolean isLastBatch) throws Exception {
    StopWatch timer = new StopWatch();
    timer.start();
    int successRec = 0;
    File fileToWrite = new File(batchProcessExportData.getFilePath() + FileSystems.getDefault().getSeparator() + fileName + BatchProcessExportData.EXT_MARC);
    FileOutputStream fileOutputStream = new FileOutputStream(fileToWrite, true);
    //String bibContent = StringUtils.join(bibDocList, "");
    if (!fileToWrite.exists()) {
        if (fileToWrite.getParentFile().mkdirs() && fileToWrite.createNewFile()) {
            //do nothing
        } else {
            LOG.error("Cannot create mrc file in the given file path :: " + fileToWrite.getPath());
            batchProcessExportData.job.setStatus(JOB_STATUS_STOPPED);
            throw new RuntimeException("Cannot create mrc file in the given file path :: " + fileToWrite.getPath());
        }
    }
    BibMarcRecordProcessor recordProcessor = new BibMarcRecordProcessor();
    MarcWriter writer = new MarcStreamWriter(fileOutputStream, "UTF-8");

    for (String bibContent : batchProcessExportData.getBibDocList()) {
        InputStream input = new ByteArrayInputStream(bibContent.getBytes());
        List<BibMarcRecord> successList = new ArrayList<>();
        Record record = null;
        OLEMarcReader marcXmlReader = new OLEMarcXmlReader(input);
        try {
            while (marcXmlReader.hasNext()) {
                if (marcXmlReader.hasErrors()) {
                    marcXmlReader.next();
                    errBuilder.append(marcXmlReader.getError().toString()).append(lineSeparator);
                    failureList.add(bibMarcRecords.get(successRec));
                    marcXmlReader.clearErrors();
                    continue;
                }
                record = marcXmlReader.next();
                writer.write(record);
                successList.add(bibMarcRecords.get(successRec));
                successRec++;
            }

        } catch (Exception ex) {
            BibMarcRecord failureRecord = bibMarcRecords.get(successRec);
            bibMarcRecords.removeAll(successList);

            // add to error list
            failureList.add(failureRecord);
            bibMarcRecords.remove(failureRecord);

            // Building Error file with reason
            String recordId = failureRecord.getRecordId();
            LOG.error("Error while parsing MARCXML to mrc data:: " + (recordId == null ? "NULL_RECORD" : "record id:: " + recordId), ex);
            batchProcessExportData.getErrBuilder().append(ERR_BIB).append(recordId == null ? "ERROR_RECORD" : recordId).append(TIME_STAMP)
                .append(new Date()).append(ERR_CAUSE).append(ex.getMessage()).append("::").append(ex.getCause().getMessage()).append(" ::For Record::").append(lineSeparator);
            batchProcessExportData.getErrBuilder().append("--------------------------------------------------------------------------------------------------").append(lineSeparator);
            batchProcessExportData.getErrBuilder().append(recordProcessor.generateXML(failureRecord)).append(lineSeparator);
            batchProcessExportData.getErrBuilder().append("--------------------------------------------------------------------------------------------------").append(lineSeparator).append(lineSeparator);

            // Converting Bib Marc records as MARCXML
            Object[] resultMap = processBibMarcRecord(bibMarcRecords, batchExportStatistics, isFirstBatch, isLastBatch);
            prepareForWrite(resultMap, bibMarcRecords, batchExportStatistics, isFirstBatch, isLastBatch);
        }
    }
    writer.close();
    timer.stop();
    return successRec;
}
 

开发者ID:VU-libtech,
项目名称:OLE-INST,
代码行数:75,
代码来源:BatchExportFetch.java

示例9: generateMarcFromXml

点赞 2

import org.marc4j.MarcWriter; //导入依赖的package包/类
/**
 * Writes the content read into a mrc file
 *
 * @throws Exception
 */
public int generateMarcFromXml() throws Exception {
    StopWatch timer = new StopWatch();
    timer.start();
    int successRec = 0;
    File fileToWrite = new File(filePath + FileSystems.getDefault().getSeparator() + fileName + EXT_MARC);
    FileOutputStream fileOutputStream = new FileOutputStream(fileToWrite, true);
    //String bibContent = StringUtils.join(bibDocList, "");
    if (!fileToWrite.exists()) {
        if (fileToWrite.getParentFile().mkdirs() && fileToWrite.createNewFile()) {
            //do nothing
        } else {
            LOG.error("Cannot create mrc file in the given file path :: " + fileToWrite.getPath());
            job.setStatus(JOB_STATUS_STOPPED);
            throw new RuntimeException("Cannot create mrc file in the given file path :: " + fileToWrite.getPath());
        }
    }
    MarcWriter writer = new MarcStreamWriter(fileOutputStream, "UTF-8");
    int errorCount = 0;
    for (String bibContent : bibDocList) {
        InputStream input = new ByteArrayInputStream(bibContent.getBytes());
        Record record = null;
        OLEMarcReader marcXmlReader = new OLEMarcXmlReader(input);
        try {
            while (marcXmlReader.hasNext()) {
                if (marcXmlReader.hasErrors()) {
                    marcXmlReader.next();
                    errBuilder.append(marcXmlReader.getError().toString()).append(lineSeparator);
                    errorCount++;
                    marcXmlReader.clearErrors();
                    continue;
                }
                record = marcXmlReader.next();
                writer.write(record);
                successRec++;
            }

        } catch (Exception ex) {
            String recordId = getRecordId(record);
            LOG.error("Error while parsing MARCXML to mrc data:: " + (recordId == null ? "NULL_RECORD" : "record id:: " + recordId), ex);
            errBuilder.append(ERR_BIB).append(recordId == null ? "ERROR_RECORD" : recordId).append(TIME_STAMP)
                    .append(new Date()).append(ERR_CAUSE).append(ex.getMessage()).append(" ::At:: ").append("generateMarcFromXml() For Record ::"+bibContent).append(lineSeparator);
        }
    }
    writer.close();
    timer.stop();
    return successRec;
}
 

开发者ID:VU-libtech,
项目名称:OLE-INST,
代码行数:53,
代码来源:BatchProcessExportData.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)