Search in sources :

Example 26 with NullOutputStream

use of org.apache.commons.io.output.NullOutputStream in project webservices-axiom by apache.

the class AttachmentsTest method testPurgeDataSource.

public void testPurgeDataSource() throws Exception {
    InputStream in = getTestResource("mtom/msg-soap-wls81.txt");
    MyLifecycleManager manager = new MyLifecycleManager();
    Attachments attachments = new Attachments(manager, in, "multipart/related;type=\"text/xml\";boundary=\"----=_Part_0_3437046.1188904239130\";start=__WLS__1188904239161__SOAP__", true, getAttachmentsDir(), "1024");
    // Read the attachment once to make sure it is buffered
    DataHandler dh = attachments.getDataHandler("__WLS__1188904239162__SOAP__");
    assertTrue(dh instanceof DataHandlerExt);
    InputStream content = dh.getInputStream();
    IOUtils.copy(content, new NullOutputStream());
    content.close();
    assertEquals(1, manager.getFileCount());
    ((DataHandlerExt) dh).purgeDataSource();
    assertEquals(0, manager.getFileCount());
    in.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) InputStream(java.io.InputStream) DataHandlerExt(org.apache.axiom.attachments.lifecycle.DataHandlerExt) DataHandler(javax.activation.DataHandler) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

Example 27 with NullOutputStream

use of org.apache.commons.io.output.NullOutputStream in project webservices-axiom by apache.

the class TestBase64StreamingWithSerialize method runTest.

@Override
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);
    elem.serialize(new NullOutputStream());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) DataSource(javax.activation.DataSource) TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

Example 28 with NullOutputStream

use of org.apache.commons.io.output.NullOutputStream in project webservices-axiom by apache.

the class AxiomTestCase method assertConsumed.

protected void assertConsumed(OMContainer container) {
    assertFalse("Expected the node to be incomplete", container.isComplete());
    boolean isConsumed;
    try {
        container.serialize(new NullOutputStream());
        isConsumed = false;
    } catch (Exception ex) {
        isConsumed = true;
    }
    assertTrue(isConsumed);
}
Also used : NullOutputStream(org.apache.commons.io.output.NullOutputStream)

Example 29 with NullOutputStream

use of org.apache.commons.io.output.NullOutputStream in project benchmarx by eMoflon.

the class MediniQVTFamiliesToPersonsConfig method launch.

/**
	 * launch the transformation in the QVT execution engine
	 * 
	 * @param direction : the desired execution direction
	 */
public void launch(String direction) {
    PrintStream ps = System.out;
    PrintStream ps_err = System.err;
    // Load the QVT relations
    try {
        System.setOut(new PrintStream(new NullOutputStream()));
        System.setErr(new PrintStream(new NullOutputStream()));
        qvtRuleSet = new FileReader(basePath + RULESET);
        this.transform(qvtRuleSet, transformation, direction);
    } catch (FileNotFoundException fileNotFoundException) {
        fileNotFoundException.printStackTrace();
        return;
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    } finally {
        System.setOut(ps);
        System.setErr(ps_err);
    }
}
Also used : PrintStream(java.io.PrintStream) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

Example 30 with NullOutputStream

use of org.apache.commons.io.output.NullOutputStream in project benchmarx by eMoflon.

the class MediniQVTFamiliesToPersons method launch.

/**
	 * launch the transformation in the QVT execution engine
	 * 
	 * @param direction : the desired execution direction
	 */
public void launch(String direction) {
    PrintStream ps = System.out;
    PrintStream ps_err = System.err;
    // Load the QVT relations
    try {
        System.setOut(new PrintStream(new NullOutputStream()));
        System.setErr(new PrintStream(new NullOutputStream()));
        qvtRuleSet = new FileReader(basePath + RULESET);
        this.transform(qvtRuleSet, transformation, direction);
    } catch (FileNotFoundException fileNotFoundException) {
        fileNotFoundException.printStackTrace();
        return;
    } catch (Throwable throwable) {
        throwable.printStackTrace();
        System.out.println(throwable.getMessage());
    } finally {
        System.setOut(ps);
        System.setErr(ps_err);
    }
}
Also used : PrintStream(java.io.PrintStream) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

Aggregations

NullOutputStream (org.apache.commons.io.output.NullOutputStream)30 InputStream (java.io.InputStream)7 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 OutputStream (java.io.OutputStream)5 DigestOutputStream (java.security.DigestOutputStream)5 MessageDigest (java.security.MessageDigest)5 FileInputStream (java.io.FileInputStream)3 PrintStream (java.io.PrintStream)3 DataHandler (javax.activation.DataHandler)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 PipedInputStream (java.io.PipedInputStream)2 ArrayList (java.util.ArrayList)2 Node (javax.jcr.Node)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 OMFactory (org.apache.axiom.om.OMFactory)2 ExceptionInputStream (org.apache.axiom.testutils.io.ExceptionInputStream)2