Package org.marc4j

Examples of org.marc4j.MarcStreamReader


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

        URL url = new URL(
                "http://www.loc.gov/standards/marcxml/Sandburg/sandburg.mrc");

        MarcReader reader = new MarcStreamReader(url.openStream());
        while (reader.hasNext()) {
            Record record = reader.next();
            System.out.println(record.toString());
        }

    }
View Full Code Here


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

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

        MarcReader reader = new MarcStreamReader(input);
        while (reader.hasNext()) {
            Record record = reader.next();
           
            // get control field with tag 008
            ControlField controlField = (ControlField) record
                    .getVariableField("008");
           
View Full Code Here

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

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

        MarcReader reader = new MarcStreamReader(input);
        Record record = reader.next();
        System.out.println(record.toString());
    }
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

        try {
            in = new FileInputStream(input);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        MarcStreamReader reader = null;
        if (encoding != null)
            reader = new MarcStreamReader(in, encoding);
        else
            reader = new MarcStreamReader(in);

        OutputStream out = null;
        if (output != null)
            try {
                out = new FileOutputStream(output);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        else
            out = System.out;

        MarcXmlWriter writer = null;

        if (stylesheet == null) {
            if (convert != null)
                writer = new MarcXmlWriter(out, "UTF8");
            else
                writer = new MarcXmlWriter(out, "UTF8");
        } else {
            Writer outputWriter = null;
            if (convert != null) {
                try {
                    outputWriter = new OutputStreamWriter(out, "UTF8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                outputWriter = new BufferedWriter(outputWriter);
            } else {
                outputWriter = new OutputStreamWriter(out);
                outputWriter = new BufferedWriter(outputWriter);
            }
            Result result = new StreamResult(outputWriter);
            Source source = new StreamSource(stylesheet);
            writer = new MarcXmlWriter(result, source);
        }
        writer.setIndent(true);

        if (convert != null) {
            CharConverter charconv = null;
            if (Constants.MARC_8_ENCODING.equals(convert))
                charconv = new AnselToUnicode();
            else if (Constants.ISO5426_ENCODING.equals(convert))
                charconv = new Iso5426ToUnicode();
            else if (Constants.ISO6937_ENCODING.equals(convert))
                charconv = new Iso6937ToUnicode();
            else {
                System.err.println("Unknown character set");
                System.exit(1);
            }
            writer.setConverter(charconv);
        }

        if (normalize)
            writer.setUnicodeNormalization(true);

        while (reader.hasNext()) {
            Record record = reader.next();
            if (Constants.MARC_8_ENCODING.equals(convert))
                record.getLeader().setCharCodingScheme('a');
            writer.write(record);
        }
        writer.close();
View Full Code Here

        InputStream input = HandleExceptionExample.class
                .getResourceAsStream("resources/error.mrc");

        try {
            MarcReader reader = new MarcStreamReader(input);
            while (reader.hasNext()) {
                Record record = reader.next();
                System.out.println(record.toString());
            }
        } catch (MarcException e) {
            System.out.println("something went wrong man!");
View Full Code Here

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

        MarcFactory factory = MarcFactory.newInstance();

        MarcReader reader = new MarcStreamReader(input);
        while (reader.hasNext()) {
            Record record = reader.next();

            DataField field = factory.newDataField("856", '4', '2');
            field.addSubfield(factory.newSubfield('3',
                "Contributor biographical information"));
            field.addSubfield(factory.newSubfield('u',
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);
        while (reader.hasNext()) {
            Record record = reader.next();
            System.out.println(record.toString());
        }

    }
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);
        while (reader.hasNext()) {
            Record record = reader.next();

            // check if the cataloging agency is DLC
            List result = record.find("040", "DLC");
            if (result.size() > 0)
                System.out.println("Agency for this record is DLC");
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);

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

        Document doc = (Document) result.getNode();
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.