Package org.apache.http.entity.mime.content

Examples of org.apache.http.entity.mime.content.InputStreamBody


    }

    @Test
    public void testNonRepeatable() throws Exception {
        final MultipartEntity entity = new MultipartEntity();
        entity.addPart("p1", new InputStreamBody(
                new ByteArrayInputStream("blah blah".getBytes()), ContentType.DEFAULT_BINARY));
        entity.addPart("p2", new InputStreamBody(
                new ByteArrayInputStream("yada yada".getBytes()), ContentType.DEFAULT_BINARY));
        Assert.assertFalse(entity.isRepeatable());
        Assert.assertTrue(entity.isChunked());
        Assert.assertTrue(entity.isStreaming());
View Full Code Here


    }

    @Test
    public void testInputStreamBody() throws Exception {
        final byte[] stuff = "Stuff".getBytes("US-ASCII");
        final InputStreamBody b1 = new InputStreamBody(new ByteArrayInputStream(stuff), "stuff");
        Assert.assertEquals(-1, b1.getContentLength());

        Assert.assertNull(b1.getCharset());
        Assert.assertEquals("stuff", b1.getFilename());
        Assert.assertEquals("application/octet-stream", b1.getMimeType());
        Assert.assertEquals("application", b1.getMediaType());
        Assert.assertEquals("octet-stream", b1.getSubType());

        Assert.assertEquals(MIME.ENC_BINARY, b1.getTransferEncoding());

        final InputStreamBody b2 = new InputStreamBody(
                new ByteArrayInputStream(stuff), ContentType.create("some/stuff"), "stuff");
        Assert.assertEquals(-1, b2.getContentLength());
        Assert.assertNull(b2.getCharset());
        Assert.assertEquals("stuff", b2.getFilename());
        Assert.assertEquals("some/stuff", b2.getMimeType());
        Assert.assertEquals("some", b2.getMediaType());
        Assert.assertEquals("stuff", b2.getSubType());

        Assert.assertEquals(MIME.ENC_BINARY, b2.getTransferEncoding());
    }
View Full Code Here

        final FormBodyPart p1 = new FormBodyPart(
                "field1",
                new FileBody(tmpfile));
        final FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
        final HttpStrictMultipart multipart = new HttpStrictMultipart("form-data", null, "foo",
                Arrays.asList(p1, p2));

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        multipart.writeTo(out);
View Full Code Here

        final FormBodyPart p2 = new FormBodyPart(
                "field2",
                new FileBody(tmpfile, ContentType.create("text/plain", "ANSI_X3.4-1968"), "test-file"));
        final FormBodyPart p3 = new FormBodyPart(
                "field3",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
        final HttpStrictMultipart multipart = new HttpStrictMultipart("form-data", null, "foo",
                Arrays.asList(p1, p2, p3));

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        multipart.writeTo(out);
View Full Code Here

        final FormBodyPart p2 = new FormBodyPart(
                "field2",
                new FileBody(tmpfile, ContentType.create("text/plain", "ANSI_X3.4-1968"), "test-file"));
        final FormBodyPart p3 = new FormBodyPart(
                "field3",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
        final HttpRFC6532Multipart multipart = new HttpRFC6532Multipart("form-data", null, "foo",
                Arrays.asList(p1, p2, p3));

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        multipart.writeTo(out);
View Full Code Here

            writer.close();
        }

        final FormBodyPart p1 = new FormBodyPart(
                "field1",
                new InputStreamBody(new FileInputStream(tmpfile), s1 + ".tmp"));
        final FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), s2 + ".tmp"));
        final HttpBrowserCompatibleMultipart multipart = new HttpBrowserCompatibleMultipart(
                "form-data", Consts.UTF_8, "foo",
                Arrays.asList(p1, p2));

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
View Full Code Here

    }

    public MultipartEntityBuilder addBinaryBody(
            final String name, final InputStream stream, final ContentType contentType,
            final String filename) {
        return addPart(name, new InputStreamBody(stream, contentType, filename));
    }
View Full Code Here

                "field1",
                new FileBody(tmpfile));
        @SuppressWarnings("resource")
        final FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
        final HttpStrictMultipart multipart = new HttpStrictMultipart("form-data", null, "foo",
                Arrays.asList(p1, p2));

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        multipart.writeTo(out);
View Full Code Here

                "field2",
                new FileBody(tmpfile, ContentType.create("text/plain", "ANSI_X3.4-1968"), "test-file"));
        @SuppressWarnings("resource")
        final FormBodyPart p3 = new FormBodyPart(
                "field3",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
        final HttpStrictMultipart multipart = new HttpStrictMultipart("form-data", null, "foo",
                Arrays.asList(p1, p2, p3));

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        multipart.writeTo(out);
View Full Code Here

                "field2",
                new FileBody(tmpfile, ContentType.create("text/plain", "ANSI_X3.4-1968"), "test-file"));
        @SuppressWarnings("resource")
        final FormBodyPart p3 = new FormBodyPart(
                "field3",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
        final HttpRFC6532Multipart multipart = new HttpRFC6532Multipart("form-data", null, "foo",
                Arrays.asList(p1, p2, p3));

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        multipart.writeTo(out);
View Full Code Here

TOP

Related Classes of org.apache.http.entity.mime.content.InputStreamBody

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.