BufferedReader reader = null; try { reader = new BufferedReader( new StringReader( IOUtils.toString(input) ) );  Template tmpl = new Template(reader); tmpl.set(TMPL_BASEPATH, httpd.getBasePath()); tmpl.set(TMPL_APIBASEPATH, httpd.getApiBasePath());  String str = tmpl.toString(); CopyUtils.copy(str, response.getOutputStream());  cache.put(loc, str);
if ( loc.endsWith("jpg") || loc.endsWith("png") || loc.endsWith("gif") ) {  CopyUtils.copy(input, response.getOutputStream());
    public void handle(String pathInContext, String pathParams,                        HttpRequest request, HttpResponse response)                throws HttpException, IOException    {        if ( !HttpRequest.__GET.equals(request.getMethod()) ) {            response.sendError(HttpResponse.__405_Method_Not_Allowed);            response.setField(HttpFields.__Allow, "GET");            return;        }                String loc = docRoot+request.getPath();                if ( cache.containsKey(loc) ) {                      // serve request from already processed cache            CopyUtils.copy((String) cache.get(loc), response.getOutputStream());            request.setHandled(true);                    } else {                    InputStream input = getClass().getResourceAsStream(loc);                LOG.debug("Found Resource '"+loc+"' in classpath? "+ (input != null ? "YES" : "NO"));                        if ( input != null ) {                                BufferedReader reader = null;                try {                    reader = new BufferedReader( new StringReader( IOUtils.toString(input) ) );                                        Template tmpl = new Template(reader);                    tmpl.set(TMPL_BASEPATH, httpd.getBasePath());                    tmpl.set(TMPL_APIBASEPATH, httpd.getApiBasePath());                                        String str = tmpl.toString();                    CopyUtils.copy(str, response.getOutputStream());                                        cache.put(loc, str);                                        request.setHandled(true);                                    } catch (TemplateCreationException ex) {                    throw new IOException("Can't create template! Message: "+ex.getMessage());                } finally {                    input.close();                    reader.close();                }                            }                    }                                                        }