[stringtemplate-interest] ST4: simple write to file method.

Collin Fagan collin.fagan at gmail.com
Sun Jan 30 07:26:36 PST 2011


Hi,

I find myself constantly writing the output of templates to files. I was
wondering if we could add a method to ST that writes directly to a file?

Something like this:

public int write(File outputFile) throws IOException {
        Writer writer = null;
        try {
            writer = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(outputFile)));
            int returnValue = write(new AutoIndentWriter(writer));
            writer.flush();
            return returnValue;
        } finally {
            try {
                if (writer != null) {
                    writer.close();
                }
            } catch (IOException ex) {
                // what can you do when a close fails???
                // nothing :(
            }
        }
    }

One might even provide a variant that lets you specify the encoding.

Does something like this sounds useful?

Thanks,

Collin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110130/ae7bb88d/attachment.html 


More information about the stringtemplate-interest mailing list