Example usage for org.apache.commons.io.output NullOutputStream nullOutputStream

List of usage examples for org.apache.commons.io.output NullOutputStream nullOutputStream

Introduction

In this page you can find the example usage for org.apache.commons.io.output NullOutputStream nullOutputStream.

Prototype

public static OutputStream nullOutputStream() 

Source Link

Document

Returns a new OutputStream which discards all bytes.

Usage

From source file:org.apache.archiva.checksum.Checksum.java

public Checksum update(InputStream stream) throws IOException {
    try (DigestInputStream dig = new DigestInputStream(stream, md)) {
        IOUtils.copy(dig, new NullOutputStream());
    }/*from w w  w. j  av  a 2 s  .  com*/
    return this;
}

From source file:org.apache.axiom.ts.AxiomTestCase.java

protected void assertConsumed(OMContainer container) {
    assertFalse("Expected the node to be incomplete", container.isComplete());
    boolean isConsumed;
    try {//from w  w w .  j a v  a  2  s .co  m
        container.serialize(new NullOutputStream());
        isConsumed = false;
    } catch (Exception ex) {
        isConsumed = true;
    }
    assertTrue(isConsumed);
}

From source file:org.apache.axiom.ts.om.document.TestSerializeAndConsume.java

protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>"))
            .getDocument();/*  w w w . ja v  a  2  s  .  c  o  m*/
    document.serializeAndConsume(new NullOutputStream());
    assertConsumed(document);
}

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 ww  w.  j a v a2  s . c om*/
    elem.serialize(new NullOutputStream());
}

From source file:org.apache.fop.events.EventProcessingTestCase.java

public void doTest(InputStream inStream, String fopConf, String expectedEventID, String mimeType)
        throws FOPException, TransformerException, IOException, SAXException {
    EventChecker eventChecker = new EventChecker(expectedEventID);
    if (fopConf != null) {
        fopFactory.setUserConfig(fopConf);
    }//  w w w  . ja v  a 2  s  .co  m
    FOUserAgent userAgent = fopFactory.newFOUserAgent();
    userAgent.getEventBroadcaster().addEventListener(eventChecker);
    Fop fop = fopFactory.newFop(mimeType, userAgent, new NullOutputStream());
    Transformer transformer = tFactory.newTransformer();
    Source src = new StreamSource(inStream);
    Result res = new SAXResult(fop.getDefaultHandler());
    transformer.transform(src, res);
    eventChecker.end();
}

From source file:org.apache.fop.fonts.TrueTypeAnsiTestCase.java

/**
 * Tests a TrueType font in WinAnsi mode.
 * @throws Exception if an error occurs//from   w w w.  j  a  va2  s.c  om
 */
public void testTrueTypeAnsi() throws Exception {
    String fontFamily = "Gladiator Bold";
    File ttfFile = new File("./test/resources/fonts/glb12.ttf");
    File workDir = new File("./build/test-results");
    if (!workDir.isDirectory()) {
        assertTrue(workDir.mkdirs());
    }
    File metricsFile = new File(workDir, ttfFile.getName() + ".xml");
    if (metricsFile.isFile()) {
        assertTrue(metricsFile.delete());
    }

    String[] args = new String[] { "-enc", "ansi", ttfFile.getCanonicalPath(), metricsFile.getCanonicalPath() };
    TTFReader.main(args);
    assertTrue(metricsFile.isFile());

    FopFactory fopFactory = FopFactory.newInstance();
    FOUserAgent ua = fopFactory.newFOUserAgent();
    PDFRenderer renderer = new PDFRenderer();
    renderer.setUserAgent(ua);
    List fontList = new java.util.ArrayList();
    List triplets = new java.util.ArrayList();
    triplets.add(new FontTriplet(fontFamily, "normal", Font.WEIGHT_NORMAL));
    EmbedFontInfo font = new EmbedFontInfo(metricsFile.toURI().toASCIIString(), true, triplets,
            ttfFile.toURI().toASCIIString(), null);
    fontList.add(font);
    renderer.addFontList(fontList);

    ua.setRendererOverride(renderer);
    OutputStream out = new NullOutputStream();

    Fop fop = fopFactory.newFop(null, ua, out);

    TransformerFactory tFactory = TransformerFactory.newInstance();
    Source src = new StreamSource(new StringReader("<root font-family='" + fontFamily + "'>Test!</root>"));
    Result res = new SAXResult(fop.getDefaultHandler());
    Transformer transformer = tFactory.newTransformer(getSourceForResource(this, "fonttest.xsl"));
    transformer.transform(src, res);
}

From source file:org.apache.fop.intermediate.AbstractIntermediateTest.java

/**
 * Tests the area tree parser by sending the parsed area tree to the PDF Renderer. Some
 * errors might be caught by the PDFRenderer.
 * @throws Exception if the test fails/*  ww  w  .ja va 2s.c  o  m*/
 */
public void testParserToPDF() throws Exception {
    OutputStream out;
    if (outputDir != null) {
        File tgtFile = new File(outputDir, testFile.getName() + ".pdf");
        out = new FileOutputStream(tgtFile);
        out = new BufferedOutputStream(out);
    } else {
        out = new NullOutputStream();
    }
    try {
        Source src = new DOMSource(intermediate);
        parseAndRender(src, out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:org.apache.fop.intermediate.AbstractIntermediateTestCase.java

/**
 * Tests the area tree parser by sending the parsed area tree to the PDF Renderer. Some
 * errors might be caught by the PDFRenderer.
 * @throws Exception if the test fails/*  ww w .  j  a  va2  s  . c o m*/
 */
public void testParserToPDF() throws Exception {
    OutputStream out;
    if (outputDir != null) {
        File tgtFile = new File(outputDir, getName() + ".pdf");
        out = new FileOutputStream(tgtFile);
        out = new BufferedOutputStream(out);
    } else {
        out = new NullOutputStream();
    }
    try {
        Source src = new DOMSource(intermediate);
        parseAndRender(src, out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:org.apache.fop.memory.MemoryEater.java

private void eatMemory(int callIndex, File foFile, int replicatorRepeats) throws Exception {
    Source src = new StreamSource(foFile);

    Transformer transformer = replicatorTemplates.newTransformer();
    transformer.setParameter("repeats", new Integer(replicatorRepeats));

    OutputStream out = new NullOutputStream(); //write to /dev/nul
    try {/*from  ww w .j  a v a2  s . co  m*/
        FOUserAgent userAgent = fopFactory.newFOUserAgent();
        userAgent.setBaseURL(foFile.getParentFile().toURI().toURL().toExternalForm());
        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);
        Result res = new SAXResult(fop.getDefaultHandler());

        transformer.transform(src, res);

        stats.notifyPagesProduced(fop.getResults().getPageCount());
        if (callIndex == 0) {
            System.out.println(foFile.getName() + " generates " + fop.getResults().getPageCount() + " pages.");
        }
        stats.checkStats();
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:org.apache.fop.render.RendererFactoryTest.java

public void testFOEventHandlerLevel() throws Exception {
    FopFactory fopFactory = FopFactory.newInstance();
    RendererFactory factory = fopFactory.getRendererFactory();
    FOUserAgent ua;//w ww . j a  v  a 2s. c o  m
    FOEventHandler foEventHandler;
    FOEventHandler overrideFOEventHandler;

    ua = fopFactory.newFOUserAgent();
    foEventHandler = factory.createFOEventHandler(ua, MimeConstants.MIME_PDF, new NullOutputStream());
    assertTrue(foEventHandler instanceof AreaTreeHandler);

    ua = fopFactory.newFOUserAgent();
    foEventHandler = factory.createFOEventHandler(ua, MimeConstants.MIME_RTF, new NullOutputStream());
    assertTrue(foEventHandler instanceof RTFHandler);

    ua = fopFactory.newFOUserAgent();
    try {
        foEventHandler = factory.createFOEventHandler(ua, "invalid/format", new NullOutputStream());
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException uoe) {
        //expected
    }

    ua = fopFactory.newFOUserAgent();
    try {
        foEventHandler = factory.createFOEventHandler(ua, MimeConstants.MIME_PDF, null);
        fail("Expected FOPException because of missing OutputStream");
    } catch (FOPException fe) {
        //expected
    }

    ua = fopFactory.newFOUserAgent();
    overrideFOEventHandler = new RTFHandler(ua, new NullOutputStream());
    ua.setFOEventHandlerOverride(overrideFOEventHandler);
    foEventHandler = factory.createFOEventHandler(ua, null, null);
    assertTrue(foEventHandler == overrideFOEventHandler);
}