{
System.out.println("Preparing to parse " + file.getName());
OutputStream os = null;
Writer writer = null;
PDDocument document = null;
try
{
document = PDDocument.load(file);
File outFile = new File(file.getParentFile().getParentFile(), "output/" + file.getName() + ".txt");
os = new FileOutputStream(outFile);
os.write( 0xFF );
os.write( 0xFE );
writer = new OutputStreamWriter(os,"UTF-16LE");
stripper.writeText(document, writer);
if (bLogResult)
{
System.out.println("Text for " + file.getName() + ":\r\n" + stripper.getText(document));
}
File expectedFile = new File(file.getParentFile().getParentFile(), "input/" + file.getName() + ".txt");
File actualFile = new File(file.getParentFile().getParentFile(), "output/" + file.getName() + ".txt");
if (!expectedFile.exists())
{
this.bFail = true;
System.err.println(
"FAILURE: Input verification file: " + expectedFile.getAbsolutePath() +
" did not exist");
return;
}
LineNumberReader expectedReader =
new LineNumberReader(new InputStreamReader(new FileInputStream(expectedFile),"UTF-16"));
LineNumberReader actualReader =
new LineNumberReader(new InputStreamReader(new FileInputStream(actualFile), "UTF-16"));
while (true)
{
String expectedLine = expectedReader.readLine();
while( expectedLine != null && expectedLine.trim().length() == 0 )
{
expectedLine = expectedReader.readLine();
}
String actualLine = actualReader.readLine();
while( actualLine != null && actualLine.trim().length() == 0 )
{
actualLine = actualReader.readLine();
}
if (!stringsEqual(expectedLine, actualLine))
{
this.bFail = true;
System.err.println("FAILURE: Line mismatch for file " + file.getName() +
" at expected line: " + expectedReader.getLineNumber() +
" at actual line: " + actualReader.getLineNumber() +
"\r\n expected line was: \"" + expectedLine + "\"" +
"\r\n actual line was: \"" + actualLine + "\"");
//lets report all lines, even though this might produce some verbose logging
//break;
}
if( expectedLine == null || actualLine==null)
{
break;
}
}
}
finally
{
if( writer != null )
{
writer.close();
}
if( os != null )
{
os.close();
}
if( document != null )
{
document.close();
}
}
}