@Test(expected = IllegalStateException.class) public void shouldNotAllowToWriteEndMoreThanOnce() { ServletPrintWriter servletPrintWriter = new ServletPrintWriter(mock(ServletOutputStream.class)); try { servletPrintWriter.writeEnd(); } catch (Throwable e) { fail("Should not throw any exception here"); } servletPrintWriter.writeEnd(); } }
/** * Flushes the output. * * @throws IOException */ public void flush() throws IOException { // It makes no sense to set chunked encoding if there is no print writer if (printWriter != null && printWriter instanceof ChunkedPrintWriter) { getHeaders().setHeader(Headers.HEADER_TRANSFER_ENCODING, TRANSFER_ENCODING_CHUNKED); } if (!isCommitted()) { flushHeaders(); } if (printWriter != null) { printWriter.writeEnd(); printWriter.flush(); } outputStream.flush(); } }
/** * {@inheritDoc} */ @Override public PrintWriter getWriter() { if (printWriter == null) { if (isTransferChunked()) { printWriter = new ChunkedPrintWriter(wrappedOutputStream); } else { printWriter = new ServletPrintWriter(wrappedOutputStream); } } return printWriter; }