Search in sources :

Example 1 with SizeAwareDataSource

use of org.apache.axiom.ext.activation.SizeAwareDataSource in project webservices-axiom by apache.

the class AttachmentsTest method testGetSizeOnDataSource.

private void testGetSizeOnDataSource(boolean useFiles) throws Exception {
    InputStream in = MTOMSample.SAMPLE1.getInputStream();
    try {
        Attachments attachments;
        if (useFiles) {
            attachments = new Attachments(in, MTOMSample.SAMPLE1.getContentType(), true, getAttachmentsDir(), "4096");
        } else {
            attachments = new Attachments(in, MTOMSample.SAMPLE1.getContentType());
        }
        DataHandler dh = attachments.getDataHandler("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org");
        DataSource ds = dh.getDataSource();
        assertTrue(ds instanceof SizeAwareDataSource);
        assertEquals(13887, ((SizeAwareDataSource) ds).getSize());
    } finally {
        in.close();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) InputStream(java.io.InputStream) SizeAwareDataSource(org.apache.axiom.ext.activation.SizeAwareDataSource) DataHandler(javax.activation.DataHandler) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) SizeAwareDataSource(org.apache.axiom.ext.activation.SizeAwareDataSource) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 DataHandler (javax.activation.DataHandler)1 DataSource (javax.activation.DataSource)1 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)1 SizeAwareDataSource (org.apache.axiom.ext.activation.SizeAwareDataSource)1 RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)1 ExceptionInputStream (org.apache.axiom.testutils.io.ExceptionInputStream)1