throws IOException, FacesException {
ExternalContext extContext = context.getExternalContext();
RenderKit renderKit = context.getRenderKit();
RenderRequest request = (RenderRequest) extContext.getRequest();
RenderResponse response = (RenderResponse) extContext.getResponse();
String contenttype = request.getResponseContentType();
if (contenttype == null) {
contenttype = "text/html";
}
String encoding = response.getCharacterEncoding();
if (encoding == null) {
encoding = "ISO-8859-1";
}
ResponseWriter writer = renderKit.createResponseWriter(NullWriter.Instance, contenttype, encoding);
contenttype = writer.getContentType();
// apply them to the response
response.setContentType(contenttype);
// Now, clone with the real writer
writer = writer.cloneWithWriter(response.getWriter());
return writer;
}