Package org.apache.http.impl.io

Examples of org.apache.http.impl.io.ContentLengthInputStream


        }
    }

    public void testBasics() throws IOException {
        String correct = "1234567890123456";
        InputStream in = new ContentLengthInputStream(new HttpDataReceiverMockup(
            EncodingUtils.getBytes(correct, CONTENT_CHARSET)), 10L);
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        byte[] buffer = new byte[50];
        int len = in.read(buffer, 0, 2);
        out.write(buffer, 0, len);
        len = in.read(buffer);
        out.write(buffer, 0, len);
       
        String result = EncodingUtils.getString(out.toByteArray(), CONTENT_CHARSET);
        assertEquals(result, "1234567890");
    }
View Full Code Here


        String result = EncodingUtils.getString(out.toByteArray(), CONTENT_CHARSET);
        assertEquals(result, "1234567890");
    }

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

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

        in = new ContentLengthInputStream(new HttpDataReceiverMockup(new byte[20]), 2L);
        in.read();
        in.read();
        assertTrue(in.skip(10) <= 0);
        assertTrue(in.skip(-1) == 0);
        assertTrue(in.read() == -1);
       
        in = new ContentLengthInputStream(new HttpDataReceiverMockup(new byte[2]), 4L);
        in.read();
        assertTrue(in.skip(2) == 1);
    }
View Full Code Here

        assertTrue(in.skip(2) == 1);
    }

    public void testClose() throws IOException {
        String correct = "1234567890123456";
        InputStream in = new ContentLengthInputStream(new HttpDataReceiverMockup(
            EncodingUtils.getBytes(correct, CONTENT_CHARSET)), 10L);
        in.close();
        in.close();
        try {
            in.read();
            fail("IOException should have been thrown");
        } catch (IOException ex) {
            // expected
        }
        byte[] tmp = new byte[10];
        try {
            in.read(tmp);
            fail("IOException should have been thrown");
        } catch (IOException ex) {
            // expected
        }
        try {
            in.read(tmp, 0, tmp.length);
            fail("IOException should have been thrown");
        } catch (IOException ex) {
            // expected
        }
    }
View Full Code Here

            entity.setContentLength(-1);
            entity.setContent(new HttpDataInputStream(datareceiver));                           
        } else {
            entity.setChunked(false);
            entity.setContentLength(len);
            entity.setContent(new ContentLengthInputStream(datareceiver, len));
        }
       
        Header contentTypeHeader = message.getFirstHeader(HTTP.CONTENT_TYPE);
        if (contentTypeHeader != null) {
            entity.setContentType(contentTypeHeader);   
View Full Code Here

    }

    private static final String CONTENT_CHARSET = "ISO-8859-1";
       
    public void testConstructors() throws Exception {
        new ContentLengthInputStream(new SessionInputBufferMockup(new byte[] {}), 10);
        try {
            new ContentLengthInputStream(null, 10);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            new ContentLengthInputStream(new SessionInputBufferMockup(new byte[] {}), -10);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
    }
View Full Code Here

        }
    }

    public void testBasics() throws IOException {
        String correct = "1234567890123456";
        InputStream in = new ContentLengthInputStream(new SessionInputBufferMockup(
            EncodingUtils.getBytes(correct, CONTENT_CHARSET)), 10L);
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        byte[] buffer = new byte[50];
        int len = in.read(buffer, 0, 2);
        out.write(buffer, 0, len);
        len = in.read(buffer);
        out.write(buffer, 0, len);
       
        String result = EncodingUtils.getString(out.toByteArray(), CONTENT_CHARSET);
        assertEquals(result, "1234567890");
    }
View Full Code Here

        String result = EncodingUtils.getString(out.toByteArray(), CONTENT_CHARSET);
        assertEquals(result, "1234567890");
    }

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

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

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

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

        assertEquals(5, in.read(new byte[20]));
    }

    public void testClose() throws IOException {
        String correct = "1234567890123456";
        InputStream in = new ContentLengthInputStream(new SessionInputBufferMockup(
            EncodingUtils.getBytes(correct, CONTENT_CHARSET)), 10L);
        in.close();
        in.close();
        try {
            in.read();
            fail("IOException should have been thrown");
        } catch (IOException ex) {
            // expected
        }
        byte[] tmp = new byte[10];
        try {
            in.read(tmp);
            fail("IOException should have been thrown");
        } catch (IOException ex) {
            // expected
        }
        try {
            in.read(tmp, 0, tmp.length);
            fail("IOException should have been thrown");
        } catch (IOException ex) {
            // expected
        }
    }
View Full Code Here

            entity.setContentLength(-1);
            entity.setContent(new HttpDataInputStream(datareceiver));                           
        } else {
            entity.setChunked(false);
            entity.setContentLength(len);
            entity.setContent(new ContentLengthInputStream(datareceiver, len));
        }
       
        Header contentTypeHeader = message.getFirstHeader(HTTP.CONTENT_TYPE);
        if (contentTypeHeader != null) {
            entity.setContentType(contentTypeHeader);   
View Full Code Here

    }

    private static final String CONTENT_CHARSET = "ISO-8859-1";
       
    public void testConstructors() throws Exception {
        new ContentLengthInputStream(new SessionInputBufferMockup(new byte[] {}), 10);
        try {
            new ContentLengthInputStream(null, 10);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            new ContentLengthInputStream(new SessionInputBufferMockup(new byte[] {}), -10);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.impl.io.ContentLengthInputStream

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.