public class MarcStreamWriter extends Object implements MarcWriter
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();
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
allowOversizeEntry |
protected String |
encoding |
protected static DecimalFormat |
format4Use |
protected static DecimalFormat |
format5Use |
protected boolean |
hasOversizeLength |
protected boolean |
hasOversizeOffset |
protected OutputStream |
out |
| Constructor and Description |
|---|
MarcStreamWriter(OutputStream out)
Constructs an instance and creates a
Writer object with the specified output stream. |
MarcStreamWriter(OutputStream out,
boolean allowOversizeRecord)
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. |
MarcStreamWriter(OutputStream out,
String encoding,
boolean allowOversizeRecord)
Constructs an instance and creates a
Writer object with the specified output stream and character
encoding. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
allowsOversizeEntry()
Returns
true if an oversized entry is allowed; else, false. |
void |
close()
Closes the writer.
|
CharConverter |
getConverter()
Returns the character converter.
|
protected byte[] |
getDataElement(String data) |
protected byte[] |
getEntry(String tag,
int length,
int start) |
void |
setAllowOversizeEntry(boolean allowOversizeEntry)
Sets whether an oversized entry is allowed.
|
void |
setConverter(CharConverter converter)
Sets the character converter.
|
void |
write(Record record)
Writes a
Record object to the writer. |
protected void |
writeLeader(Leader ldr) |
protected OutputStream out
protected String encoding
protected boolean allowOversizeEntry
protected boolean hasOversizeOffset
protected boolean hasOversizeLength
protected static DecimalFormat format4Use
protected static DecimalFormat format5Use
public MarcStreamWriter(OutputStream out)
Writer object with the specified output stream.public MarcStreamWriter(OutputStream out, String encoding)
Writer object with the specified output stream and character
encoding.public MarcStreamWriter(OutputStream out, boolean allowOversizeRecord)
Writer object with the specified output stream.public MarcStreamWriter(OutputStream out, String encoding, boolean allowOversizeRecord)
Writer object with the specified output stream and character
encoding.public CharConverter getConverter()
getConverter in interface MarcWriterpublic void setConverter(CharConverter converter)
setConverter in interface MarcWriterconverter - the character converterpublic void write(Record record)
Record object to the writer.write in interface MarcWriterrecord - - the Record objectprotected void writeLeader(Leader ldr) throws IOException
IOExceptionpublic void close()
close in interface MarcWriterprotected byte[] getDataElement(String data) throws IOException
IOExceptionprotected byte[] getEntry(String tag, int length, int start) throws IOException
IOExceptionpublic boolean allowsOversizeEntry()
true if an oversized entry is allowed; else, false.public void setAllowOversizeEntry(boolean allowOversizeEntry)
allowOversizeEntry - Copyright © 2014 FreeLibrary. All Rights Reserved.