Package net.sourceforge.purrpackage.recording

Examples of net.sourceforge.purrpackage.recording.Closer


    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();
        }
    }
View Full Code Here

TOP

Related Classes of net.sourceforge.purrpackage.recording.Closer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.