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();