Search in sources :

Example 36 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class GZIPHelper method compressGzip.

public static InputStream compressGzip(String contentEncoding, InputStream in) throws IOException {
    if (isGzip(contentEncoding)) {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(os);
        try {
            IOHelper.copy(in, gzip);
            gzip.finish();
            return new ByteArrayInputStream(os.toByteArray());
        } finally {
            IOHelper.close(gzip, "gzip");
            IOHelper.close(os, "byte array output stream");
        }
    } else {
        return in;
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 37 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class BeanWithInputStreamBodyTest method testBeanWithInputStreamBodyMethod.

public void testBeanWithInputStreamBodyMethod() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").bean(MyCoolBean.class, "doSomething").to("mock:result");
        }
    });
    context.start();
    getMockEndpoint("mock:result").expectedBodiesReceived("There is 11 bytes");
    InputStream bais = new ByteArrayInputStream("Hello World".getBytes());
    template.sendBody("direct:start", bais);
    assertMockEndpointsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 38 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class BeanParameterBindingStreamCachingTest method testBean.

public void testBean() throws Exception {
    getMockEndpoint("mock:result").expectedBodiesReceived("abcABC");
    template.sendBody("direct:start", new ByteArrayInputStream("aBc".getBytes()));
    assertMockEndpointsSatisfied();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 39 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class MockEndpointTest method testSetMultipleExpectedHeaders4.

public void testSetMultipleExpectedHeaders4() throws Exception {
    // to test the header value with Stream which can only be consumed once
    InputStream is = new ByteArrayInputStream("Test".getBytes());
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedHeaderReceived("foo", 123);
    mock.expectedHeaderReceived("bar", "Test");
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("foo", 123);
    map.put("bar", is);
    template.sendBodyAndHeaders("direct:a", "Hello World", map);
    mock.assertIsSatisfied();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 40 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class LogInputStreamTest method testB.

public void testB() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:b");
    mock.expectedMessageCount(1);
    mock.message(0).body().convertToString().isEqualTo("Hello World");
    InputStream is = new ByteArrayInputStream("Hello World".getBytes());
    template.sendBody("direct:b", is);
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)6879 Test (org.junit.Test)2274 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1791 InputStream (java.io.InputStream)1531 IOException (java.io.IOException)1400 DataInputStream (java.io.DataInputStream)600 ObjectInputStream (java.io.ObjectInputStream)597 X509Certificate (java.security.cert.X509Certificate)397 CertificateFactory (java.security.cert.CertificateFactory)355 ObjectOutputStream (java.io.ObjectOutputStream)333 File (java.io.File)279 ArrayList (java.util.ArrayList)270 Certificate (java.security.cert.Certificate)234 HashMap (java.util.HashMap)212 DataOutputStream (java.io.DataOutputStream)200 FileInputStream (java.io.FileInputStream)182 InputStreamReader (java.io.InputStreamReader)180 Test (org.testng.annotations.Test)171 Document (org.w3c.dom.Document)143 Map (java.util.Map)138