@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) { } }