RenderTemplateMiddleware extends AbstractWebMiddleware<HttpRequest, NRES> { protected void render(TemplatedHttpResponse response) { InputStream is = response.getBodyAsStream(); ReadableByteChannel channel = Channels.newChannel(is); ByteBuffer buf = ByteBuffer.allocate(4096); buf.mark(); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { int read; while ((read = channel.read(buf)) >= 0) { baos.write(buf.array(), 0, read); buf.reset(); } String body = new String(baos.toByteArray(), StandardCharsets.UTF_8); response.setBody(body); } catch (IOException ex) { throw new FalteringEnvironmentException(ex); } }  @Override HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, NRES, ?, ?> chain); void setUserFunctions(Map<String, Function<List, Object>> userFunctions);  }
@Test void render() { final TemplatedHttpResponse response = TemplatedHttpResponse.create("template1"); response.setBody("hello"); sut.render(response); assertThat(response.getBodyAsString()).isEqualTo("hello"); }