Close readers provided by TemplateLoader

This commit is contained in:
Alexander Schrab
2015-03-04 18:45:55 +01:00
parent f24d4a7795
commit 2ab053ce35
@@ -273,7 +273,8 @@ public class Mustache
/** Handles loading partial templates. */ /** Handles loading partial templates. */
public interface TemplateLoader public interface TemplateLoader
{ {
/** Returns a reader for the template with the supplied name. /** Returns a reader for the template with the supplied name.
* Reader will be closed by callee.
* @throws Exception if the template could not be loaded for any reason. */ * @throws Exception if the template could not be loaded for any reason. */
Reader getTemplate (String name) throws Exception; Reader getTemplate (String name) throws Exception;
} }
@@ -741,7 +742,9 @@ public class Mustache
// itself (see issue #13) // itself (see issue #13)
if (_template == null) { if (_template == null) {
try { try {
_template = _comp.compile(_comp.loader.getTemplate(_name)); Reader t = _comp.loader.getTemplate(_name);
_template = _comp.compile(t);
t.close();
} catch (Exception e) { } catch (Exception e) {
if (e instanceof RuntimeException) { if (e instanceof RuntimeException) {
throw (RuntimeException)e; throw (RuntimeException)e;