public void flushContentToWrappedResponse() throws IOException {
   if (caw != null) {
     pw.flush();
     caw.writeTo(response.getWriter());
     caw.reset();
   } else if (bawos != null) {
     try {
       bawos.writeTo(response.getWriter(), response.getCharacterEncoding());
     } catch (IllegalStateException ise) {
       bawos.writeTo(response.getPortletOutputStream());
     }
     bawos.resetByteArray();
   }
 }
  public static void init(RenderRequest request, RenderResponse response) {
    String outputEncoding = response.getCharacterEncoding();
    //        if (FacesResponseUtil.isMyFacesFacesContext(request)) {
    // for MyFaces
    // MyFaces needs this workaround code because of the implementation
    // issue..
    PortletSession session = request.getPortletSession(true);
    // FacesContext facesContext = FacesContext.getCurrentInstance();
    FacesContext facesContext = FacesResponseUtil.getMyFacesFacesContext(request);
    boolean existResonseWriter = true;
    if (facesContext == null) {
      existResonseWriter = false;
    } else {
      if (facesContext.getResponseWriter() == null) {
        existResonseWriter = false;
      }
    }

    Object oldBufferedResonseStream =
        session.getAttribute(FacesResponseConstants.BUFFERED_RESPONSE_STREAM);
    if (existResonseWriter && oldBufferedResonseStream != null) {
      ((BufferedResponseStream) oldBufferedResonseStream).recycle();
    } else {
      BufferedResponseStream bufferedResponseStream = new BufferedResponseStream(outputEncoding);
      session.setAttribute(FacesResponseConstants.BUFFERED_RESPONSE_STREAM, bufferedResponseStream);
    }
    //        } else {
    //            // for JSF implementation whice does not pass FacesContext from
    //            // processAction to render
    //            BufferedResponseStream bufferedResponseStream = new BufferedResponseStream(
    //                    outputEncoding);
    //            request.setAttribute(
    //                    FacesResponseConstants.BUFFERED_RESPONSE_STREAM,
    //                    bufferedResponseStream);
    //        }
  }
 public String getCharacterEncoding() {
   return response.getCharacterEncoding();
 }