From 2ab053ce357e929dc5b44142299eb7235189ad54 Mon Sep 17 00:00:00 2001 From: Alexander Schrab Date: Wed, 4 Mar 2015 18:45:55 +0100 Subject: [PATCH] Close readers provided by TemplateLoader --- src/main/java/com/samskivert/mustache/Mustache.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/samskivert/mustache/Mustache.java b/src/main/java/com/samskivert/mustache/Mustache.java index fb36961..7e05e26 100644 --- a/src/main/java/com/samskivert/mustache/Mustache.java +++ b/src/main/java/com/samskivert/mustache/Mustache.java @@ -273,7 +273,8 @@ public class Mustache /** Handles loading partial templates. */ 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. */ Reader getTemplate (String name) throws Exception; } @@ -741,7 +742,9 @@ public class Mustache // itself (see issue #13) if (_template == null) { try { - _template = _comp.compile(_comp.loader.getTemplate(_name)); + Reader t = _comp.loader.getTemplate(_name); + _template = _comp.compile(t); + t.close(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException)e;