String encoding;
FileFinder finder;
public void read(String sourceFileName, Callback callback) throws Exception {
Closer c = new Closer();
final Source source = finder.getSource(sourceFileName);
if (source == null) {
throw new SourceReaderException("Could not find source file for "
+ sourceFileName);
}
c.register(new Closeable() {
@Override
public void close() throws IOException {
source.close();
}
});
BufferedReader br = null;
try {
br = readerFor(source);
c.register(br);
} catch (UnsupportedEncodingException e) {
throw new SourceReaderException("Encoding problem for source file "
+ sourceFileName + ": " + e.getMessage());
} catch (Throwable t) {
throw new SourceReaderException(
"Could not create reader for source file " + sourceFileName
+ ": " + t.toString());
}
try {
String lineStr;
while ((lineStr = br.readLine()) != null) {
callback.lineRead(lineStr);
}
} catch (Exception e) {
c.doNotThrow();
throw new SourceReaderException("Could not read " + sourceFileName
+ ": " + e.toString());
} finally {
c.closeAll();
}
}