diff options
-rw-r--r-- | src/test/java/fi/iki/elonen/ChunkedInputStreamTest.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/java/fi/iki/elonen/ChunkedInputStreamTest.java b/src/test/java/fi/iki/elonen/ChunkedInputStreamTest.java new file mode 100644 index 0000000..d0fd9a1 --- /dev/null +++ b/src/test/java/fi/iki/elonen/ChunkedInputStreamTest.java @@ -0,0 +1,31 @@ +package fi.iki.elonen; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.io.StringBufferInputStream; +import java.nio.charset.StandardCharsets; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class ChunkedInputStreamTest +{ + + @Test + @DisplayName( "Simple decoding test" ) + public void testChunkedInput() throws IOException + { + String data = "4\r\nWiki\r\n7\r\npedia i\r\nB;1h\ra\nllo\r\nn \r\nchunks.\r\n0\r\n\r\n"; + String expected = "Wikipedia in \r\nchunks."; + ChunkedInputStream stream = new ChunkedInputStream( new StringBufferInputStream( data ) ); + StringBuilder sb = new StringBuilder(); + int n; + byte[] buf = new byte[ 6 ]; + while ( ( n = stream.read( buf ) ) > 0 ) { + sb.append( new String( buf, 0, n, StandardCharsets.US_ASCII ) ); + } + assertEquals( sb.toString(), expected ); + } + +} |