Package org.apache.http.impl

Examples of org.apache.http.impl.SessionInputBufferMock


    @Test
    public void testBasics() throws IOException {
        final String correct = "1234567890123456";
        final InputStream in = new ContentLengthInputStream(
                new SessionInputBufferMock(correct, Consts.ISO_8859_1), 10L);
        final ByteArrayOutputStream out = new ByteArrayOutputStream();

        final byte[] buffer = new byte[50];
        int len = in.read(buffer, 0, 2);
        out.write(buffer, 0, len);
View Full Code Here


        in.close();
    }

    @Test
    public void testSkip() throws IOException {
        InputStream in = new ContentLengthInputStream(new SessionInputBufferMock(new byte[20]), 10L);
        Assert.assertEquals(10, in.skip(10));
        Assert.assertTrue(in.read() == -1);

        in = new ContentLengthInputStream(new SessionInputBufferMock(new byte[20]), 10L);
        in.read();
        Assert.assertEquals(9, in.skip(10));
        Assert.assertTrue(in.read() == -1);
        in.close();

        in = new ContentLengthInputStream(new SessionInputBufferMock(new byte[20]), 2L);
        in.read();
        in.read();
        Assert.assertTrue(in.skip(10) <= 0);
        Assert.assertTrue(in.skip(-1) == 0);
        Assert.assertTrue(in.read() == -1);
        in.close();

        in = new ContentLengthInputStream(new SessionInputBufferMock(new byte[20]), 10L);
        Assert.assertEquals(5,in.skip(5));
        Assert.assertEquals(5, in.read(new byte[20]));
        in.close();
    }
View Full Code Here

    }

    @Test
    public void testAvailable() throws IOException {
        final InputStream in = new ContentLengthInputStream(
                new SessionInputBufferMock(new byte[] {1, 2, 3}), 3L);
        Assert.assertEquals(0, in.available());
        in.read();
        Assert.assertEquals(2, in.available());
        in.close();
    }
View Full Code Here

    }

    @Test
    public void testClose() throws IOException {
        final String correct = "1234567890123456-";
        final SessionInputBuffer inbuffer = new SessionInputBufferMock(correct, Consts.ISO_8859_1);
        final InputStream in = new ContentLengthInputStream(inbuffer, 16L);
        in.close();
        in.close();
        try {
            in.read();
            Assert.fail("IOException should have been thrown");
        } catch (final IOException ex) {
            // expected
        }
        final byte[] tmp = new byte[10];
        try {
            in.read(tmp);
            Assert.fail("IOException should have been thrown");
        } catch (final IOException ex) {
            // expected
        }
        try {
            in.read(tmp, 0, tmp.length);
            Assert.fail("IOException should have been thrown");
        } catch (final IOException ex) {
            // expected
        }
        Assert.assertEquals('-', inbuffer.read());
    }
View Full Code Here

    }

    @Test
    public void testTruncatedContent() throws IOException {
        final String correct = "1234567890123456";
        final SessionInputBuffer inbuffer = new SessionInputBufferMock(correct, Consts.ISO_8859_1);
        final InputStream in = new ContentLengthInputStream(inbuffer, 32L);
        final byte[] tmp = new byte[32];
        final int byteRead = in.read(tmp);
        Assert.assertEquals(16, byteRead);
        try {
View Full Code Here

            "HTTP/1.1 200 OK\r\n" +
            "Server: whatever\r\n" +
            "Date: some date\r\n" +
            "Set-Cookie: c1=stuff\r\n" +
            "\r\n";
        final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);

        final DefaultHttpResponseParser parser = new DefaultHttpResponseParser(inbuffer);
        final HttpResponse httpresponse = parser.parse();

        final StatusLine statusline = httpresponse.getStatusLine();
View Full Code Here

        Assert.assertEquals(3, headers.length);
    }

    @Test
    public void testConnectionClosedException() throws Exception {
        final SessionInputBuffer inbuffer = new SessionInputBufferMock(new byte[] {});

        final DefaultHttpResponseParser parser = new DefaultHttpResponseParser(inbuffer);
        try {
            parser.parse();
            Assert.fail("NoHttpResponseException should have been thrown");
View Full Code Here

            "HTTP\000/1.1 200\000 OK\r\n" +
            "Server: wha\000tever\r\n" +
            "Date: some date\r\n" +
            "Set-Coo\000kie: c1=stuff\r\n" +
            "\000\r\n";
        final SessionInputBuffer inbuffer = new SessionInputBufferMock(
                new TimeoutByteArrayInputStream(s.getBytes(Consts.ASCII)), 16);

        final DefaultHttpResponseParser parser = new DefaultHttpResponseParser(inbuffer);

        int timeoutCount = 0;
View Full Code Here

    // Test for when buffer is larger than chunk size
    @Test
    public void testChunkedInputStreamLargeBuffer() throws IOException {
        final ChunkedInputStream in = new ChunkedInputStream(
                new SessionInputBufferMock(CHUNKED_INPUT, Consts.ISO_8859_1));
        final byte[] buffer = new byte[300];
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        int len;
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer, 0, len);
View Full Code Here

    //Test for when buffer is smaller than chunk size.
    @Test
    public void testChunkedInputStreamSmallBuffer() throws IOException {
        final ChunkedInputStream in = new ChunkedInputStream(
                new SessionInputBufferMock(CHUNKED_INPUT, Consts.ISO_8859_1));

        final byte[] buffer = new byte[7];
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        int len;
        while ((len = in.read(buffer)) > 0) {
View Full Code Here

TOP

Related Classes of org.apache.http.impl.SessionInputBufferMock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.