Package org.marc4j

Examples of org.marc4j.MarcWriter


        }
       
        try {
            OutputStream os = new FileOutputStream(tempFile);
            try {
                MarcWriter writer = new MarcXmlWriter(os, true);
               
                MarcPermissiveStreamReader reader = new MarcPermissiveStreamReader(
                    inputStream, true, true);
                while (reader.hasNext()) {
                    Record record = reader.next();
                    writer.write(record);
                }
                writer.close();
            } finally {
                try {
                    os.close();
                } catch (IOException e) {
                    // Just ignore - not much we can do anyway
View Full Code Here


      pos.close();
      log.debug("attempt to read marcxml from pipe");
      if (reader.hasNext()) {
        Record record = reader.next();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        MarcWriter writer = new MarcStreamWriter(baos);
        writer.write(record);
        result = baos.toByteArray();
        log.debug("Result of transform to marc: "+new String(result));
      }
      else {
        log.warn("No marc record found in reader stream");
View Full Code Here

        boolean to_utf_8 = true;
      
        InputStream inNorm;
        InputStream inPerm;
        OutputStream patchedRecStream = null;
        MarcWriter patchedRecs = null;
        ErrorHandler errorHandler = new ErrorHandler();
        try
        {
            inNorm = new FileInputStream(file);
            readerNormal = new MarcPermissiveStreamReader(inNorm, false, to_utf_8);
            inPerm = new FileInputStream(file);
            readerPermissive = new MarcPermissiveStreamReader(inPerm, errorHandler, to_utf_8, "BESTGUESS");
        }
        catch (FileNotFoundException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (args.length > 1)
        {
            try
            {
                patchedRecStream = new FileOutputStream(new File(args[1]));
                patchedRecs = new MarcStreamWriter(patchedRecStream);
            }
            catch (FileNotFoundException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        while (readerNormal.hasNext() && readerPermissive.hasNext())
        {
            Record recNorm;
            Record recPerm;
            recPerm = readerPermissive.next();
            String strPerm = recPerm.toString();
            try {
                recNorm = readerNormal.next();
            }
            catch (MarcException me)
            {
                if (verbose)
                {
                    out.println("Fatal Exception: "+ me.getMessage());
                    dumpErrors(out, errorHandler);
                    showDiffs(out, null, strPerm);
                    out.println("-------------------------------------------------------------------------------------");
                }
                continue;
            }
            String strNorm = recNorm.toString();
            if (!strNorm.equals(strPerm))
            {
                if (verbose)
                {
                    dumpErrors(out, errorHandler);
                    showDiffs(out, strNorm, strPerm);
                    out.println("-------------------------------------------------------------------------------------");
                   
                }
                if (patchedRecs != null)
                {
                    patchedRecs.write(recPerm);
                }
            }
            else if (errorHandler.hasErrors())
            {
                if (verbose)
                {
                    out.println("Results identical, but errors reported");
                    dumpErrors(out, errorHandler);
                    showDiffs(out, strNorm, strPerm);
                    out.println("-------------------------------------------------------------------------------------");
                }
                if (patchedRecs != null)
                {
                    patchedRecs.write(recPerm);
                }
            }
            else if (veryverbose)
            {
                showDiffs(out, strNorm, strPerm);               
View Full Code Here

        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

            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

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

        MarcReader reader = new MarcStreamReader(input);
        MarcWriter writer = new MarcXmlWriter(System.out, true);

        AnselToUnicode converter = new AnselToUnicode();
        writer.setConverter(converter);

        while (reader.hasNext()) {
            Record record = reader.next();
            writer.write(record);
        }
        writer.close();
    }
View Full Code Here

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

        MarcReader reader = new MarcStreamReader(input);
        MarcWriter writer = new MarcStreamWriter(System.out, "UTF8");

        AnselToUnicode converter = new AnselToUnicode();
        writer.setConverter(converter);

        while (reader.hasNext()) {
            Record record = reader.next();
            writer.write(record);
        }
        writer.close();
    }
View Full Code Here

                .getResourceAsStream("resources/brkrtest.mrc");

        OutputStream out = new FileOutputStream("c:/temp/summerland.xml");

        MarcReader reader = new MarcStreamReader(input);
        MarcWriter writer = new MarcXmlWriter(out, true);

        AnselToUnicode converter = new AnselToUnicode();
        writer.setConverter(converter);

        while (reader.hasNext()) {
            Record record = reader.next();
            writer.write(record);
        }
        writer.close();
    }
View Full Code Here

TOP

Related Classes of org.marc4j.MarcWriter

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.