/** * {@inheritDoc} */ @Override public void println() { // Overwrites the original new line character synchronized (lock) { print(NEW_LINE); } }
@Test public void shouldSerializeDataProperly() { ByteArrayOutputStream out = new ByteArrayOutputStream(1024); 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 shouldAppendNewLineProperly() { ByteArrayOutputStream out = new ByteArrayOutputStream(1024); ChunkedPrintWriter printWriter = new ChunkedPrintWriter(out); printWriter.print("Wiki"); printWriter.println(); printWriter.flush(); assertThat(new String(out.toByteArray()), is("4\r\nWiki\r\n2\r\n\r\n\r\n")); }
/** * {@inheritDoc} */ @Override public PrintWriter getWriter() { if (printWriter == null) { if (isTransferChunked()) { printWriter = new ChunkedPrintWriter(wrappedOutputStream); } else { printWriter = new ServletPrintWriter(wrappedOutputStream); } } return printWriter; }
@Test public void shouldEncodeLengthAsHex() { ByteArrayOutputStream out = new ByteArrayOutputStream(1024); 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")); } }