Search in sources :

Example 91 with InputStream

use of java.io.InputStream 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 92 with InputStream

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

the class ConverterTest method testConvertStringAndStreams.

public void testConvertStringAndStreams() throws Exception {
    InputStream inputStream = converter.convertTo(InputStream.class, "bar");
    assertNotNull(inputStream);
    String text = converter.convertTo(String.class, inputStream);
    assertEquals("Converted to String", "bar", text);
}
Also used : InputStream(java.io.InputStream)

Example 93 with InputStream

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

the class XmlConverterTest method testToInputStreamFromDocument.

public void testToInputStreamFromDocument() throws Exception {
    XmlConverter conv = new XmlConverter();
    Document doc = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar</foo>");
    InputStream is = conv.toInputStream(doc, null);
    assertNotNull(is);
    assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, is));
}
Also used : InputStream(java.io.InputStream) Document(org.w3c.dom.Document)

Example 94 with InputStream

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

the class XmlConverterTest method testToSaxSourceByInputStream.

public void testToSaxSourceByInputStream() throws Exception {
    XmlConverter conv = new XmlConverter();
    InputStream is = context.getTypeConverter().convertTo(InputStream.class, "<foo>bar</foo>");
    SAXSource out = conv.toSAXSource(is, null);
    assertNotNull(out);
    assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
Also used : SAXSource(javax.xml.transform.sax.SAXSource) InputStream(java.io.InputStream)

Example 95 with InputStream

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

the class CachedOutputStreamTest method testCacheStreamToFileAndCloseStreamEncrypted.

public void testCacheStreamToFileAndCloseStreamEncrypted() throws Exception {
    // set some stream or 8-bit block cipher transformation name
    context.getStreamCachingStrategy().setSpoolChiper("RC4");
    context.start();
    CachedOutputStream cos = new CachedOutputStream(exchange);
    cos.write(TEST_STRING.getBytes("UTF-8"));
    cos.flush();
    File file = new File("target/cachedir");
    String[] files = file.list();
    assertEquals("we should have a temp file", 1, files.length);
    assertTrue("The content is written", new File(file, files[0]).length() > 10);
    java.io.FileInputStream tmpin = new java.io.FileInputStream(new File(file, files[0]));
    String temp = toString(tmpin);
    assertTrue("The content is not encrypted", temp.length() > 0 && temp.indexOf("aaa") < 0);
    tmpin.close();
    StreamCache cache = cos.newStreamCache();
    assertTrue("Should get the FileInputStreamCache", cache instanceof FileInputStreamCache);
    temp = toString((InputStream) cache);
    ((InputStream) cache).close();
    assertEquals("we should have a temp file", 1, files.length);
    assertEquals("Cached a wrong file", temp, TEST_STRING);
    exchange.getUnitOfWork().done(exchange);
    try {
        cache.reset();
        // The stream is closed, so the temp file is gone.
        fail("we expect the exception here");
    } catch (Exception exception) {
    // do nothing
    }
    files = file.list();
    assertEquals("we should have no temp file", 0, files.length);
    IOHelper.close(cos);
}
Also used : StreamCache(org.apache.camel.StreamCache) InputStream(java.io.InputStream) File(java.io.File) IOException(java.io.IOException)

Aggregations

InputStream (java.io.InputStream)12635 IOException (java.io.IOException)4626 ByteArrayInputStream (java.io.ByteArrayInputStream)2818 Test (org.junit.Test)2722 FileInputStream (java.io.FileInputStream)2443 File (java.io.File)1750 OutputStream (java.io.OutputStream)1173 InputStreamReader (java.io.InputStreamReader)1091 BufferedInputStream (java.io.BufferedInputStream)1075 URL (java.net.URL)1032 FileOutputStream (java.io.FileOutputStream)821 ByteArrayOutputStream (java.io.ByteArrayOutputStream)782 BufferedReader (java.io.BufferedReader)742 FileNotFoundException (java.io.FileNotFoundException)587 Properties (java.util.Properties)580 ArrayList (java.util.ArrayList)562 HttpURLConnection (java.net.HttpURLConnection)424 HashMap (java.util.HashMap)397 GZIPInputStream (java.util.zip.GZIPInputStream)342 Metadata (org.apache.tika.metadata.Metadata)319