Package org.marc4j

Examples of org.marc4j.MarcStreamReader


   * create the canonica XML for this object
   */
  public Document getCanonicalXML(Object native_object) throws RecordBuilderException {
    org.w3c.dom.Document retval = null;
    try {
      MarcReader reader = new MarcStreamReader(new ByteArrayInputStream((byte[])native_object));
      javax.xml.transform.dom.DOMResult result = new javax.xml.transform.dom.DOMResult();
      MarcXmlWriter writer = new MarcXmlWriter(result);
      writer.setConverter(new org.marc4j.converter.impl.AnselToUnicode());
      if (reader.hasNext()) {
        Record record = (Record) reader.next();
        writer.write(record);
      }
      writer.close();

      retval = (Document) result.getNode();
View Full Code Here


{
    private String marcRecord;

    public MarcRecord(byte[] recordData) throws RecordFormatException
    {
        MarcStreamReader reader = new MarcStreamReader(new ByteArrayInputStream(recordData));

        if (reader.hasNext())
        {
            this.marcRecord = reader.next().toString();
        }
        else
        {
            throw new RecordFormatException("No MARC record could be read from input data");
        }
View Full Code Here

    public void testMarcStreamReader() throws Exception {
        int i = 0;
        InputStream input = getClass().getResourceAsStream(
                "resources/chabon.mrc");
        MarcStreamReader reader = new MarcStreamReader(input);
        while (reader.hasNext()) {
            Record record = reader.next();
            System.err.println(record.toString());
            i++;
        }
        input.close();
        assertEquals(2, i);
View Full Code Here

        int counter = 0;

        InputStream input = getClass().getResourceAsStream(
                "resources/summerland.mrc");

        MarcStreamReader reader = new MarcStreamReader(input);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        MarcStreamWriter writer = new MarcStreamWriter(out);
        while (reader.hasNext()) {
            Record record = reader.next();
            writer.write(record);
            counter++;
        }
        input.close();
        writer.close();

        assertEquals(1, counter);

        counter = 0;

        input = new ByteArrayInputStream(out.toByteArray());

        reader = new MarcStreamReader(input);
        while (reader.hasNext()) {
            Record record = reader.next();
            counter++;
        }
        input.close();

        assertEquals(1, counter);
View Full Code Here

        InputStream input = getClass().getResourceAsStream(
                "resources/brkrtest.mrc");

        int counter = 0;

        MarcStreamReader reader = new MarcStreamReader(input);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        MarcStreamWriter writer = new MarcStreamWriter(out, "UTF8");
        writer.setConverter(new AnselToUnicode());
        while (reader.hasNext()) {
            Record record = reader.next();
            writer.write(record);
            counter++;
        }
        input.close();
        writer.close();

        assertEquals(8, counter);

        counter = 0;

        input = new ByteArrayInputStream(out.toByteArray());

        reader = new MarcStreamReader(input, "UTF8");

        while (reader.hasNext()) {
            Record record = reader.next();
            counter++;
        }
        input.close();

        assertEquals(8, counter);
View Full Code Here

    public static void main(String args[]) throws Exception {

        InputStream input = ReadMarcExample.class
                .getResourceAsStream("resources/summerland.mrc");

        MarcReader reader = new MarcStreamReader(input);
        MarcWriter writer = new MarcStreamWriter(System.out);
        while (reader.hasNext()) {
            Record record = reader.next();
            writer.write(record);
        }
        writer.close();
    }
View Full Code Here

    Record record = null;

    public void setUp() throws Exception {
        InputStream input = getClass().getResourceAsStream(
                "resources/summerland.mrc");
        MarcReader reader = new MarcStreamReader(input);
        while (reader.hasNext()) {
            record = reader.next();
        }
        input.close();
    }
View Full Code Here

        Result result = new StreamResult(System.out);

        InputStream input = ReadMarcExample.class
                .getResourceAsStream("resources/summerland.mrc");
        MarcReader reader = new MarcStreamReader(input);

        MarcXmlWriter writer = new MarcXmlWriter(result, stylesheet);
        writer.setConverter(new AnselToUnicode());
        while (reader.hasNext()) {
            Record record = (Record) reader.next();
            writer.write(record);
        }
        writer.close();
    }
View Full Code Here

            // create the input stream
            InputStream input = ReadMarcExample.class
                    .getResourceAsStream("resources/summerland.mrc");

            // parse the input
            MarcReader reader = new MarcStreamReader(input);
            MarcWriter writer = new MarcXmlWriter(result);
            while (reader.hasNext()) {
                Record record = reader.next();
                writer.write(record);
            }
            writer.close();
           
            out.close();
View Full Code Here

    public static void main(String args[]) throws Exception {

        InputStream input = ReadMarcExample.class
                .getResourceAsStream("resources/summerland.mrc");
        MarcReader reader = new MarcStreamReader(input);

        // OutputFormat format = new OutputFormat("xml", "UTF-8", true);

        // XMLSerializer serializer = new XMLSerializer(System.out, format);
        // Result result = new SAXResult(serializer.asContentHandler());

        // MarcXmlWriter writer = new MarcXmlWriter(result);
        // writer.setConverter(new AnselToUnicode());
        while (reader.hasNext()) {
            Record record = reader.next();
            // writer.write(record);
        }
        // writer.close();

    }
View Full Code Here

TOP

Related Classes of org.marc4j.MarcStreamReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.