コード例 #1
0
  /* ------------------------------------------------------------ */
  public PrintWriter getWriter() throws java.io.IOException {
    if (_outputState == DISABLED) return __nullServletWriter;

    if (_outputState != NO_OUT && _outputState != WRITER_OUT) throw new IllegalStateException();

    // If we are switching modes, flush output to try avoid overlaps.
    if (_out != null) _out.flush();

    /* if there is no writer yet */
    if (_writer == null) {
      /* get encoding from Content-Type header */
      String encoding = _httpResponse.getCharacterEncoding();

      if (encoding == null) {
        if (_servletHttpRequest != null) {
          /* implementation of educated defaults */
          String mimeType = _httpResponse.getMimeType();
          encoding =
              _servletHttpRequest
                  .getServletHandler()
                  .getHttpContext()
                  .getEncodingByMimeType(mimeType);
        }
        if (encoding == null) encoding = StringUtil.__ISO_8859_1;
        _httpResponse.setCharacterEncoding(encoding, true);
      }

      /* construct Writer using correct encoding */
      _writer = new ServletWriter(_httpResponse.getOutputStream(), encoding);
    }
    _outputState = WRITER_OUT;
    return _writer;
  }
コード例 #2
0
  /* ------------------------------------------------------------ */
  public void flushBuffer() throws IOException {
    if (((HttpOutputStream) _httpResponse.getOutputStream()).isClosed()) return;

    if (_writer != null) _writer.flush();
    if (_out != null) _out.flush();
    if (_writer == null && _out == null) _httpResponse.getOutputStream().flush();
    if (!_httpResponse.isCommitted()) _httpResponse.commit();
  }
コード例 #3
0
 /* ------------------------------------------------------------ */
 void setOutputState(int s) throws IOException {
   if (s < 0) {
     _outputState = DISABLED;
     if (_writer != null) _writer.disable();
     _writer = null;
     if (_out != null) _out.disable();
     _out = null;
   } else _outputState = s;
 }