summaryrefslogtreecommitdiffstats
path: root/src/test/java/fi/iki/elonen/ChunkedInputStreamTest.java
blob: d0fd9a1b966bf802ac292da064f6bf0268645cfa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 );
	}

}