Example usage for javax.activation FileDataSource getInputStream

List of usage examples for javax.activation FileDataSource getInputStream

Introduction

In this page you can find the example usage for javax.activation FileDataSource getInputStream.

Prototype

public InputStream getInputStream() throws IOException 

Source Link

Document

This method will return an InputStream representing the the data and will throw an IOException if it can not do so.

Usage

From source file:org.openehealth.ipf.platform.camel.lbs.http.process.AbstractLbsHttpTest.java

@Test
public void testMultipartSendOnly() throws Exception {
    Exchange sendExchange = new DefaultExchange(camelContext);

    FileDataSource dataSource1 = new FileDataSource(file);
    InputStream inputStream = dataSource1.getInputStream();
    ResourceDataSource resource1 = factory.createResource("test", "text/plain", "text", "first", inputStream);
    inputStream.close();/*from   www.  j  a  va 2s .co m*/

    ByteArrayDataSource dataSource2 = new ByteArrayDataSource("testdata".getBytes(), "text/plain");
    inputStream = dataSource2.getInputStream();
    ResourceDataSource resource2 = factory.createResource("test", "text/plain", "text", "second",
            dataSource2.getInputStream());
    inputStream.close();

    ResourceList resources = new ResourceList();
    resources.add(resource1);
    resources.add(resource2);
    sendExchange.getIn().setBody(resources);
    sendExchange.setPattern(ExchangePattern.InOut);

    mock.expectedMessageCount(1);
    mock.whenAnyExchangeReceived(outputGenerator);

    Exchange output = producerTemplate.send(ENDPOINT_SEND_ONLY, sendExchange);

    mock.assertIsSatisfied();

    assertEquals("testoutput", output.getOut().getBody(String.class));

    Map<String, String> receivedContent = outputGenerator.getReceivedContent();
    assertEquals(2, receivedContent.size());
    assertEquals("blu bla", receivedContent.get("first"));
    assertEquals("testdata", receivedContent.get("second"));
}