protected InputStream createContentInputStream( final long len, final SessionInputBuffer buffer, final InputStream inputStream) { if (len > 0) { return new ContentLengthInputStream(buffer, inputStream, len); } else if (len == 0) { return EmptyInputStream.INSTANCE; } else if (len == ContentLengthStrategy.CHUNKED) { return new ChunkedInputStream(buffer, inputStream, this.h1Config); } else { return new IdentityInputStream(buffer, inputStream); } }
protected InputStream createContentInputStream( final long len, final SessionInputBuffer buffer, final InputStream inputStream) { if (len > 0) { return new ContentLengthInputStream(buffer, inputStream, len); } else if (len == 0) { return EmptyInputStream.INSTANCE; } else if (len == ContentLengthStrategy.CHUNKED) { return new ChunkedInputStream(buffer, inputStream, this.h1Config); } else { return new IdentityInputStream(buffer, inputStream); } }
@Test public void testAvailable() throws Exception { final byte[] input = new byte[] {'a', 'b', 'c'}; final ByteArrayInputStream inputStream = new ByteArrayInputStream(input); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(new BasicHttpTransportMetrics(), 16, 16, 1024, null); final IdentityInputStream in = new IdentityInputStream(inBuffer, inputStream); in.read(); Assert.assertEquals(2, in.available()); in.close(); }
@Test public void testAvailableInStream() throws Exception { final byte[] input = new byte[] {'a', 'b', 'c', 'd', 'e', 'f'}; final ByteArrayInputStream inputStream = new ByteArrayInputStream(input); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(new BasicHttpTransportMetrics(), 16, 0, 1024, null); final IdentityInputStream in = new IdentityInputStream(inBuffer, inputStream); final byte[] tmp = new byte[3]; Assert.assertEquals(3, in.read(tmp)); Assert.assertEquals(3, in.available()); in.close(); }
@Test public void testClosedCondition() throws Exception { final byte[] input = new byte[] {'a', 'b', 'c'}; final ByteArrayInputStream inputStream = new ByteArrayInputStream(input); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16); final IdentityInputStream in = new IdentityInputStream(inBuffer, inputStream); in.close(); in.close(); Assert.assertEquals(0, in.available()); final byte[] tmp = new byte[2]; try { in.read(tmp, 0, tmp.length); Assert.fail("StreamClosedException expected"); } catch (final StreamClosedException expected) { } try { in.read(); Assert.fail("StreamClosedException expected"); } catch (final StreamClosedException expected) { } }
@Test public void testBasicRead() throws Exception { final byte[] input = new byte[] {'a', 'b', 'c'}; final ByteArrayInputStream inputStream = new ByteArrayInputStream(input); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16); final IdentityInputStream in = new IdentityInputStream(inBuffer, inputStream); final byte[] tmp = new byte[2]; Assert.assertEquals(2, in.read(tmp, 0, tmp.length)); Assert.assertEquals('a', tmp[0]); Assert.assertEquals('b', tmp[1]); Assert.assertEquals('c', in.read()); Assert.assertEquals(-1, in.read(tmp, 0, tmp.length)); Assert.assertEquals(-1, in.read()); Assert.assertEquals(-1, in.read(tmp, 0, tmp.length)); Assert.assertEquals(-1, in.read()); in.close(); }