ChunkedPrintWriter extends ServletPrintWriter { @Override public void writeEnd() { super.writeEnd(); super.write(END_LINE); } ChunkedPrintWriter(final OutputStream out); @Override void println(); @Override void write(final String str); @Override void writeEnd();  }
@Test public void shouldSerializeDataProperly() { ByteArrayOutputStream out = new ByteArrayOutputStream(ONE_KILO); ChunkedPrintWriter printWriter = new ChunkedPrintWriter(out); printWriter.print("Wiki"); printWriter.print("pedia"); printWriter.print(" in\r\n\r\nchunks."); printWriter.writeEnd(); printWriter.flush(); assertThat(new String(out.toByteArray()), is("4\r\nWiki\r\n5\r\npedia\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n")); }
@Test public void shouldEncodeLengthAsHex() { ByteArrayOutputStream out = new ByteArrayOutputStream(ONE_KILO); ChunkedPrintWriter printWriter = new ChunkedPrintWriter(out); printWriter.print("SomeTextLongerThanSixteenCharacters"); printWriter.flush(); assertThat(new String(out.toByteArray()), is("23\r\nSomeTextLongerThanSixteenCharacters\r\n")); printWriter.writeEnd(); printWriter.flush(); assertThat(new String(out.toByteArray()), is("23\r\nSomeTextLongerThanSixteenCharacters\r\n0\r\n\r\n")); }