private static InputStream render ( final String folder , final InputStream template , final Map < String , Object > params ) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; final Writer writer = new Utf8OutputStreamContent ( baos ) ; final VelocityEngine engine = new VelocityEngine ( ) ; engine . setProperty ( "file.resource.loader.path" , folder ) ; engine . evaluate ( new VelocityContext ( params ) , writer , "" , new Utf8InputStreamContent ( template ) ) ; writer . close ( ) ; return new ByteArrayInputStream ( baos . toByteArray ( ) ) ; }
Render it .