/**
   * @see {@link ExternalContext#getResponseOutputStream()}
   * @since JSF 2.0
   */
  @Override
  public OutputStream getResponseOutputStream() throws IOException {

    if (portletResponse instanceof MimeResponse) {

      if (facesImplementationServletResponse != null) {
        logger.debug(
            "Delegating to AFTER_VIEW_CONTENT servletResponse=[{0}]",
            facesImplementationServletResponse);

        return facesImplementationServletResponse.getOutputStream();
      } else {
        MimeResponse mimeResponse = (MimeResponse) portletResponse;

        return mimeResponse.getPortletOutputStream();
      }
    } else {

      if (manageIncongruities) {
        return incongruityContext.getResponseOutputStream();
      } else {
        throw new IllegalStateException();
      }
    }
  }
  @Override
  public ServletOutputStream getOutputStream() throws IOException {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      OutputStream portletOutputStream = mimeResponse.getPortletOutputStream();

      ServletOutputStream servletOutputStream = new GenericServletOutputStream(portletOutputStream);

      return servletOutputStream;
    } else {
      return new NullServletOutputStream();
    }
  }