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