org.marc4j
Class MarcStreamWriter

java.lang.Object
  extended by org.marc4j.MarcStreamWriter
All Implemented Interfaces:
MarcWriter

public class MarcStreamWriter
extends Object
implements MarcWriter

Class for writing MARC record objects in ISO 2709 format.

The following example reads a file with MARCXML records and outputs the record set in ISO 2709 format:

 InputStream input = new FileInputStream("marcxml.xml");
 MarcXmlReader reader = new MarcXmlReader(input);
 MarcWriter writer = new MarcStreamWriter(System.out);
 while (reader.hasNext()) {
     Record record = reader.next();
     writer.write(record);
 }
 writer.close();
 

To convert characters like for example from UCS/Unicode to MARC-8 register a CharConverter implementation:

 InputStream input = new FileInputStream("marcxml.xml");
 MarcXmlReader reader = new MarcXmlReader(input);
 MarcWriter writer = new MarcStreamWriter(System.out);
 writer.setConverter(new UnicodeToAnsel());
 while (reader.hasNext()) {
     Record record = reader.next();
     writer.write(record);
 }
 writer.close();
 

Version:
$Revision: 1.4 $
Author:
Bas Peters

Constructor Summary
MarcStreamWriter(OutputStream out)
          Constructs an instance and creates a Writer object with the specified output stream.
MarcStreamWriter(OutputStream out, String encoding)
          Constructs an instance and creates a Writer object with the specified output stream and character encoding.
 
Method Summary
 void close()
          Closes the writer.
 CharConverter getConverter()
          Returns the character converter.
 void setConverter(CharConverter converter)
          Sets the character converter.
 void write(Record record)
          Writes a Record object to the writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarcStreamWriter

public MarcStreamWriter(OutputStream out)
Constructs an instance and creates a Writer object with the specified output stream.


MarcStreamWriter

public MarcStreamWriter(OutputStream out,
                        String encoding)
Constructs an instance and creates a Writer object with the specified output stream and character encoding.

Method Detail

getConverter

public CharConverter getConverter()
Returns the character converter.

Specified by:
getConverter in interface MarcWriter
Returns:
CharConverter the character converter

setConverter

public void setConverter(CharConverter converter)
Sets the character converter.

Specified by:
setConverter in interface MarcWriter
Parameters:
converter - the character converter

write

public void write(Record record)
Writes a Record object to the writer.

Specified by:
write in interface MarcWriter
Parameters:
record - - the Record object

close

public void close()
Closes the writer.

Specified by:
close in interface MarcWriter


Copyright © 2002-2006 Bas Peters. All Rights Reserved.