Example usage for javax.activation DataHandler DataHandler

List of usage examples for javax.activation DataHandler DataHandler

Introduction

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

Prototype

public DataHandler(URL url) 

Source Link

Document

Create a DataHandler instance referencing a URL.

Usage

From source file:de.alpharogroup.email.data.sources.ByteArrayDataSourceTest.java

/**
 * Test method for the constructor of {@link ByteArrayDataSource}.
 *
 * @throws IOException//from  ww w . j  a  va 2 s  .co  m
 *             Signals that an I/O exception has occurred.
 */
@Test
public void testByteArrayDataSource() throws IOException {
    final String expected = "Sample Data";
    final DataSource dataSource = new ByteArrayDataSource(expected.getBytes(),
            Mimetypes.TEXT_PLAIN.getMimetype());
    final DataHandler dataHandler = new DataHandler(dataSource);
    final String rawString = EmailExtensions.getString(dataHandler);
    final String actual = new String(Base64.decodeBase64(rawString));
    assertEquals("Not expected content", expected, actual);
}

From source file:org.wso2.appserver.integration.common.clients.JaggeryApplicationUploaderClient.java

private DataHandler createDataHandler(String filePath) throws MalformedURLException {
    URL url = new URL("file://" + filePath);
    return new DataHandler(url);
}

From source file:org.apache.axiom.attachments.impl.PartOnMemory.java

public DataHandler getDataHandler() throws MessagingException {
    DataSource ds = new MyByteArrayDataSource();
    return new DataHandler(ds);
}

From source file:org.apache.camel.component.mail.MailSplitAttachmentsTest.java

@Before
public void setup() {
    // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
    endpoint = context.getEndpoint("smtp://james@mymailserver.com?password=secret");
    exchange = endpoint.createExchange();
    Message in = exchange.getIn();//from   w ww. jav  a  2 s .com
    in.setBody("Hello World");
    in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));
    in.addAttachment("license.txt",
            new DataHandler(new FileDataSource("src/main/resources/META-INF/LICENSE.txt")));
}

From source file:se.inera.axel.shs.camel.LargeShsMessageTypeConverterTest.java

@DirtiesContext
@Test/* ww  w .j  a  va 2  s  .c  o m*/
public void testLargeFileToStream() throws Exception {
    Assert.assertNotNull(testShsMessage);

    InputStream largeInput = new NullInputStream(100_000_000);

    testShsMessage.getDataParts().remove(0);
    DataPart dataPart = new DataPart(
            new DataHandler(new InputStreamDataSource(largeInput, "application/x-iso9660-image")));
    dataPart.setContentType("application/x-iso9660-image");
    dataPart.setFileName("largefile");
    dataPart.setTransferEncoding("base64");
    dataPart.setDataPartType("iso");

    testShsMessage.getDataParts().add(dataPart);

    resultEndpoint.expectedMessageCount(1);
    template.sendBody("direct:convertToStream", testShsMessage);

    resultEndpoint.assertIsSatisfied();
    List<Exchange> exchanges = resultEndpoint.getReceivedExchanges();
    Exchange exchange = exchanges.get(0);

    InputStream result = exchange.getIn().getMandatoryBody(InputStream.class);

    IOUtils.skipFully(result, 100_000_000);

}

From source file:org.apache.axiom.ts.om.text.TestBase64Streaming.java

protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement elem = factory.createOMElement("test", null);
    // Create a data source that would eat up all memory when loaded. If the test
    // doesn't fail with an OutOfMemoryError, we know that the OMText implementation
    // supports streaming.
    DataSource ds = new TestDataSource('A', Runtime.getRuntime().maxMemory());
    OMText text = factory.createOMText(new DataHandler(ds), false);
    elem.addChild(text);//from   w ww .  j  av a 2s  .  co  m
    elem.serialize(new NullOutputStream());
}

From source file:org.wso2.carbon.appfactory.core.retrieve.RetrieveArtifactService.java

/**
 *
 * @param applicationId Application ID/*from   www  .j a  v  a  2 s  .c o  m*/
 * @param version Application Version
 * @param revision Application revision
 * @param tenantDomain Tenant domain of application
 * @return {@link DataHandler}
 */
public DataHandler retrieveArtifact(String applicationId, String version, String revision,
        String tenantDomain) {
    String fileName = null;
    File file = null;
    ArtifactStorage storage = ServiceHolder.getArtifactStorage();

    try {
        file = storage.retrieveArtifact(applicationId, version, revision, tenantDomain);
        fileName = file.getAbsolutePath();

    } catch (AppFactoryException e) {
        e.printStackTrace();
    }

    FileDataSource dataSource = new FileDataSource(fileName);
    DataHandler fileDataHandler = new DataHandler(dataSource);
    return fileDataHandler;
}

From source file:org.wso2.brs.rule.test.CallChargingTestCase.java

@Test(groups = { "wso2.brs" })
public void uploadCallChargingService() throws Exception {

    String samplesDir = System.getProperty("samples.dir");
    String CallChargingServiceAAR = samplesDir + File.separator
            + "callcharging.service/service/target/CallChargingService.aar";
    log.info(CallChargingServiceAAR);//from www  .j a va  2  s .c o m
    FileDataSource fileDataSource = new FileDataSource(CallChargingServiceAAR);
    DataHandler dataHandler = new DataHandler(fileDataSource);
    getRuleServiceFileUploadClient().uploadService("CallChargingService.aar", dataHandler);

}

From source file:org.wso2.brs.rule.test.OrderApprovalTestCase.java

@Test(groups = { "wso2.brs" })
public void uploadOrderApprovalService() throws Exception {
    String samplesDir = System.getProperty("samples.dir");
    String OrderApprovalServiceAAR = samplesDir + File.separator
            + "orderApproval.service/service/target/OrderApprovalService.aar";
    log.info(OrderApprovalServiceAAR);/* w  w  w. java2 s. co m*/
    FileDataSource fileDataSource = new FileDataSource(OrderApprovalServiceAAR);
    DataHandler dataHandler = new DataHandler(fileDataSource);
    getRuleServiceFileUploadClient().uploadService("OrderApprovalService.aar", dataHandler);

}

From source file:org.wso2.dss.integration.test.sparql.SPARQLServiceTestCase.java

@BeforeClass(alwaysRun = true)
public void serviceDeployment() throws Exception {
    super.init();
    serviceEndPoint = getServiceUrlHttp(serviceName);
    String resourceFileLocation = getResourceLocation();
    deployService(serviceName, new DataHandler(new URL("file:///" + resourceFileLocation + File.separator
            + "dbs" + File.separator + "sparql" + File.separator + "SPARQLDataService.dbs")));
    log.info(serviceName + " uploaded");
}