code: @Override
  	public PrintWriter getWriter() throws IOException {
  		if (writer == null) {
  			if (stream != null) {
  				throw new IllegalStateException(
  						"getOutputStream() has already been called for this response");
  			}
  
  			try {
  				getOutputStream();
  			} catch (final IllegalStateException e) {
  				// issue 488: if a filter has called getWriter() before the MonitoringFilter, we can't call getOutputStream()
  				writer = super.getWriter();
  				return writer;
  			}
  
  			final ServletOutputStream outputStream = getOutputStream();
  			final String charEnc = getHttpServletResponse().getCharacterEncoding();
  			// HttpServletResponse.getCharacterEncoding() shouldn't return null
  			// according the spec, so feel free to remove that "if"
  			final PrintWriter result;
  			if (charEnc == null) {
  				result = new PrintWriter(outputStream);
  			} else {
  				result = new PrintWriter(new OutputStreamWriter(outputStream, charEnc));
  			}
  			writer = result;
  		}
  		return writer;
  	}
docs: {@inheritDoc}