/** * Writes the end of chunked message. */ @Override public void writeEnd() { super.writeEnd(); super.write(END_LINE); } }
@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(); } }