Search in sources :

Example 86 with InputStream

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

the class FileProducerCharsetUTFtoISOConvertBodyToTest method testFileProducerCharsetUTFtoISOConvertBodyTo.

public void testFileProducerCharsetUTFtoISOConvertBodyTo() throws Exception {
    oneExchangeDone.matchesMockWaitTime();
    File file = new File("target/charset/output.txt");
    assertTrue("File should exist", file.exists());
    InputStream fis = IOHelper.buffered(new FileInputStream(file));
    byte[] buffer = new byte[100];
    int len = fis.read(buffer);
    assertTrue("Should read data: " + len, len != -1);
    byte[] data = new byte[len];
    System.arraycopy(buffer, 0, data, 0, len);
    fis.close();
    for (byte b : data) {
        log.info("loaded byte: {}", b);
    }
    // data should be in iso, where the danish ae is -26
    assertEquals(4, data.length);
    assertEquals(65, data[0]);
    assertEquals(66, data[1]);
    assertEquals(67, data[2]);
    assertEquals(-26, data[3]);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 87 with InputStream

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

the class FileProducerCharsetUTFtoUTFTest method testFileProducerCharsetUTFtoUTF.

public void testFileProducerCharsetUTFtoUTF() throws Exception {
    oneExchangeDone.matchesMockWaitTime();
    File file = new File("target/charset/output.txt");
    assertTrue("File should exist", file.exists());
    InputStream fis = IOHelper.buffered(new FileInputStream(file));
    byte[] buffer = new byte[100];
    int len = fis.read(buffer);
    assertTrue("Should read data: " + len, len != -1);
    byte[] data = new byte[len];
    System.arraycopy(buffer, 0, data, 0, len);
    fis.close();
    // data should be in utf, where the danish ae is -61 -90
    assertEquals(5, data.length);
    assertEquals(65, data[0]);
    assertEquals(66, data[1]);
    assertEquals(67, data[2]);
    assertEquals(-61, data[3]);
    assertEquals(-90, data[4]);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 88 with InputStream

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

the class FileProducerCharsetUTFOptimizedTest method testFileProducerCharsetUTFOptimized.

public void testFileProducerCharsetUTFOptimized() throws Exception {
    oneExchangeDone.matchesMockWaitTime();
    File file = new File("target/charset/output.txt");
    assertTrue("File should exist", file.exists());
    InputStream fis = IOHelper.buffered(new FileInputStream(file));
    byte[] buffer = new byte[100];
    int len = fis.read(buffer);
    assertTrue("Should read data: " + len, len != -1);
    byte[] data = new byte[len];
    System.arraycopy(buffer, 0, data, 0, len);
    fis.close();
    // data should be in utf, where the danish ae is -61 -90
    assertEquals(5, data.length);
    assertEquals(65, data[0]);
    assertEquals(66, data[1]);
    assertEquals(67, data[2]);
    assertEquals(-61, data[3]);
    assertEquals(-90, data[4]);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 89 with InputStream

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

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

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