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
{
try
{
if (vw != null)
{
/*
* flush and put back into the pool
* don't close to allow us to play
* nicely with others.
*/
vw.flush();
/*
* 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);
}
}
catch (Exception e)