try {
in = new FileInputStream(new File(input));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
MarcXmlReader reader = null;
if (stylesheet == null)
reader = new MarcXmlReader(in);
else {
Source source = new StreamSource(stylesheet);
reader = new MarcXmlReader(in, source);
}
OutputStream out = null;
if (output != null)
try {
out = new FileOutputStream(output);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
else
out = System.out;
MarcStreamWriter writer = null;
if (encoding != null)
writer = new MarcStreamWriter(out, encoding);
else
writer = new MarcStreamWriter(out);
if (convert != null) {
CharConverter charconv = null;
if (Constants.MARC_8_ENCODING.equals(convert))
charconv = new UnicodeToAnsel();
else if (Constants.ISO5426_ENCODING.equals(convert))
charconv = new UnicodeToIso5426();
else if (Constants.ISO6937_ENCODING.equals(convert))
charconv = new UnicodeToIso6937();
else {
System.err.println("Unknown character set");
System.exit(1);
}
writer.setConverter(charconv);
}
while (reader.hasNext()) {
Record record = reader.next();
if (Constants.MARC_8_ENCODING.equals(convert))
record.getLeader().setCharCodingScheme(' ');
writer.write(record);
}
writer.close();