Here are the examples of the java api class bboss.org.apache.velocity.io.VelocityWriter taken from open source projects.
1. VelocityServlet#mergeTemplate()
Project: bboss
File: VelocityServlet.java
File: VelocityServlet.java
/** * merges the template with the context. Only override this if you really, really * really need to. (And don't call us with questions if it breaks :) * * @param template template object returned by the handleRequest() method * @param context context created by the createContext() method * @param response servlet reponse (use this to get the output stream or Writer * @throws ResourceNotFoundException * @throws ParseErrorException * @throws MethodInvocationException * @throws IOException * @throws UnsupportedEncodingException * @throws Exception */ protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException, UnsupportedEncodingException, Exception { ServletOutputStream output = response.getOutputStream(); VelocityWriter vw = null; // ASSUMPTION: response.setContentType() has been called. String encoding = response.getCharacterEncoding(); try { vw = (VelocityWriter) writerPool.get(); if (vw == null) { vw = new VelocityWriter(new OutputStreamWriter(output, encoding), 4 * 1024, true); } else { vw.recycle(new OutputStreamWriter(output, encoding)); } template.merge(context, vw); } finally { if (vw != null) { try { /* * flush and put back into the pool * don't close to allow us to play * nicely with others. */ vw.flush(); } catch (IOException e) { } /* * Clear the VelocityWriter's reference to its * internal OutputStreamWriter to allow the latter * to be GC'd while vw is pooled. */ vw.recycle(null); writerPool.put(vw); } } }