while((charsRead = inp.read(charBuffer)) > 0) {
sb.append(charBuffer,0,charsRead);
}
String[] parts = filename.split("\\.");
String ext = parts[parts.length-1].toLowerCase();
DocumentProcessor dp = documentProcessorManager.getProcessorForType(ext);
// where to put the output
OutputStream output;
if (outputFilename != null)
output = new BufferedOutputStream(new FileOutputStream(outputFilename));
else
output = System.out;
// write it there
output.write(dp.process(sb.toString()).getBytes(charset));
// close if file
if (outputFilename != null)
output.close();
}