Example usage for org.apache.commons.io.output DeferredFileOutputStream getByteCount

List of usage examples for org.apache.commons.io.output DeferredFileOutputStream getByteCount

Introduction

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

Prototype

public long getByteCount() 

Source Link

Document

Returns the number of bytes that have been written to this output stream.

Usage

From source file:org.apache.maven.plugin.surefire.report.StatelessXmlReporter.java

private void addOutputStreamElement(OutputStreamWriter outputStreamWriter, OutputStream fw,
        EncodingOutputStream eos, XMLWriter xmlWriter, DeferredFileOutputStream stdOut, String name) {
    if (stdOut != null && stdOut.getByteCount() > 0) {

        xmlWriter.startElement(name);//from  ww w . java2s  .c om

        try {
            xmlWriter.writeText(""); // Cheat sax to emit element
            outputStreamWriter.flush();
            stdOut.close();
            eos.getUnderlying().write("<![CDATA[".getBytes()); // emit cdata
            stdOut.writeTo(eos);
            eos.getUnderlying().write("]]>".getBytes());
            eos.flush();
        } catch (IOException e) {
            throw new ReporterException("When writing xml report stdout/stderr", e);
        }
        xmlWriter.endElement();
    }
}