CacheableHttpServletResponse extends HttpServletResponseWrapper { @Override public PrintWriter getWriter() throws IOException { if (out != null) return out; if (osCalled) throw new IllegalStateException("An output stream has already been allocated"); String encoding = getCharacterEncoding(); if (encoding == null) { encoding = DEFAULT_ENCODING; setCharacterEncoding(encoding); } try { if (tx == null || tx.getFilter() == null) out = new PrintWriter(new OutputStreamWriter(super.getOutputStream(), encoding)); else out = new PrintWriter(new BufferedWriter(new FilterWriter(new OutputStreamWriter(new TeeOutputStream(super.getOutputStream(), tx.getOutputStream()), encoding), tx.getFilter(), contentType))); } catch (UnsupportedEncodingException e) { throw new IOException(e.getMessage()); } if (out == null) throw new IOException("Unable to allocate writer"); return out; } CacheableHttpServletResponse(HttpServletResponse response); CacheTransaction startTransaction(CacheHandle handle,
      StreamFilter filter); @Override PrintWriter getWriter(); @Override ServletOutputStream getOutputStream(); boolean isValid(); CacheTransaction getTransaction(); @Override void setContentType(String type); @Override void flushBuffer(); @Override void addHeader(String name, String value); @Override void setHeader(String name, String value); @Override void addDateHeader(String name, long date); @Override void addIntHeader(String name, int value); @Override void setDateHeader(String name, long date); @Override void setIntHeader(String name, int value);  }
@Test public void testGetWriter() throws Exception { assertNotNull(response.getWriter()); try { response.getOutputStream(); fail(); } catch (IllegalStateException e) { } }