Search in sources :

Example 41 with ByteArrayInputStream

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

the class LogInputStreamTest method testD.

public void testD() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:d");
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("Hello World");
    InputStream is = new ByteArrayInputStream("Hello World".getBytes());
    template.sendBody("direct:d", is);
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 42 with ByteArrayInputStream

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

the class ByteArrayInputStreamCacheTest method testByteArrayInputStream.

public void testByteArrayInputStream() throws Exception {
    ByteArrayInputStreamCache cache = new ByteArrayInputStreamCache(new ByteArrayInputStream("<foo>bar</foo>".getBytes()));
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    cache.writeTo(bos);
    String s = context.getTypeConverter().convertTo(String.class, bos);
    assertEquals("<foo>bar</foo>", s);
    IOHelper.close(cache, bos);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 43 with ByteArrayInputStream

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

the class StaxConverterTest method testToInputSreamByXmlStreamReader.

public void testToInputSreamByXmlStreamReader() throws Exception {
    StringReader src = new StringReader(TEST_XML_7000);
    XMLStreamReader xreader = null;
    InputStream in = null;
    try {
        xreader = context.getTypeConverter().mandatoryConvertTo(XMLStreamReader.class, src);
        in = context.getTypeConverter().mandatoryConvertTo(InputStream.class, xreader);
        // verify
        InputStream expected = new ByteArrayInputStream(TEST_XML_7000.getBytes("utf-8"));
        byte[] tmp1 = new byte[512];
        byte[] tmp2 = new byte[512];
        for (; ; ) {
            int n1 = 0;
            int n2 = 0;
            try {
                n1 = expected.read(tmp1, 0, tmp1.length);
                n2 = in.read(tmp2, 0, tmp2.length);
            } catch (IOException e) {
                fail("unable to read data");
            }
            assertEquals(n1, n2);
            if (n2 < 0) {
                break;
            }
            assertTrue(Arrays.equals(tmp1, tmp2));
        }
    } finally {
        if (xreader != null) {
            xreader.close();
        }
        if (in != null) {
            in.close();
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StringReader(java.io.StringReader) IOException(java.io.IOException)

Example 44 with ByteArrayInputStream

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

the class IOConverterTest method testInputStreamToString.

public void testInputStreamToString() throws Exception {
    String data = "46°37'00\"N\"";
    ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes("UTF-8"));
    Exchange exchange = new DefaultExchange(context);
    exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
    String result = IOConverter.toString(is, exchange);
    assertEquals("Get a wrong result", data, result);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 45 with ByteArrayInputStream

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

the class MultiCastParallelAndStreamCachingTest method testReaderCache.

/**
     * Tests the ReaderCache.
     * 
     * The sent InputStreamReader is transformed to a ReaderCache before the
     * multi-cast processor is called.
     * 
     * @throws Exception
     */
public void testReaderCache() throws Exception {
    // sharp-s
    String abcScharpS = "ABCß";
    MockEndpoint mock = getMockEndpoint("mock:resulta");
    mock.expectedBodiesReceived(abcScharpS);
    mock = getMockEndpoint("mock:resultb");
    mock.expectedBodiesReceived(abcScharpS);
    InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(abcScharpS.getBytes("ISO-8859-1")), "ISO-8859-1");
    template.sendBody("direct:start", isr);
    assertMockEndpointsSatisfied();
}
Also used : InputStreamReader(java.io.InputStreamReader) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream)

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