Package org.apache.commons.io.output

Examples of org.apache.commons.io.output.CountingOutputStream


    }

    @Override
    public void writeTo(OutputStream output)
    {
        CountingOutputStream countingOutput = new CountingOutputStream(output);
        super.writeTo(countingOutput);

        report.setCompressedSize(countingOutput.getCount());

        writeSizeReport();
    }
View Full Code Here


        final ISWFWriterFactory writerFactory = SWFWriterAndSizeReporter.getSWFWriterFactory(
                targetSettings.getSizeReport());
        final ISWFWriter writer = writerFactory.createSWFWriter(swfTarget, compression, targetSettings.isDebugEnabled());
       
        // Write out the SWF, counting how many bytes were written.
        final CountingOutputStream output =
                new CountingOutputStream(outputStream);

        writer.writeTo(output);
        final int swfSize = output.getCount();
        return swfSize;
    }
View Full Code Here

        return this.map.get(new Integer(key));
    }
   
    /** {@inheritDoc} */
    protected int output(OutputStream stream) throws IOException {
        CountingOutputStream cout = new CountingOutputStream(stream);
        Writer writer = PDFDocument.getWriterFor(cout);
        if (hasObjectNumber()) {
            writer.write(getObjectID());
        }
       
        writer.write('[');
        boolean first = true;
        Iterator iter = this.map.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry)iter.next();
            if (!first) {
                writer.write(" ");
            }
            first = false;
            formatObject(entry.getKey(), cout, writer);
            writer.write(" ");
            formatObject(entry.getValue(), cout, writer);
        }
        writer.write(']');
       
        if (hasObjectNumber()) {
            writer.write("\nendobj\n");
        }
       
        writer.flush();
        return cout.getCount();
    }
View Full Code Here

        out.write(buf);
        bytesWritten += buf.length;
       
        //Stream contents
        CloseBlockerOutputStream cbout = new CloseBlockerOutputStream(out);
        CountingOutputStream cout = new CountingOutputStream(cbout);
        OutputStream filteredOutput = getFilterList().applyFilters(cout);
        outputRawStreamData(filteredOutput);
        filteredOutput.close();
        refLength.setNumber(new Integer(cout.getCount()));
        bytesWritten += cout.getCount();
           
        //Stream trailer
        buf = encode("\nendstream");
        out.write(buf);
        bytesWritten += buf.length;
View Full Code Here

     * {@inheritDoc}
     */
    protected int output(OutputStream stream) throws IOException {
        setupFilterList();

        CountingOutputStream cout = new CountingOutputStream(stream);
        Writer writer = PDFDocument.getWriterFor(cout);
        writer.write(getObjectID());
        //int length = 0;
       
        StreamCache encodedStream = null;
        PDFNumber refLength = null;
        final Object lengthEntry;
        if (getDocument().isEncodingOnTheFly()) {
            refLength = new PDFNumber();
            getDocumentSafely().registerObject(refLength);
            lengthEntry = refLength;
        } else {
            encodedStream = encodeStream();
            lengthEntry = new Integer(encodedStream.getSize() + 1);
        }
       
        populateStreamDict(lengthEntry);
        writeDictionary(cout, writer);
       
        //Send encoded stream to target OutputStream
        writer.flush();
        if (encodedStream == null) {
            encodeAndWriteStream(cout, refLength);
        } else {
            outputStreamData(encodedStream, cout);
            encodedStream.clear(); //Encoded stream can now be discarded
        }
       
        writer.write("\nendobj\n");
        writer.flush();
        return cout.getCount();
    }
View Full Code Here

        return this.entries.get(name);
    }
   
    /** {@inheritDoc} */
    protected int output(OutputStream stream) throws IOException {
        CountingOutputStream cout = new CountingOutputStream(stream);
        Writer writer = PDFDocument.getWriterFor(cout);
        if (hasObjectNumber()) {
            writer.write(getObjectID());
        }
       
        writeDictionary(cout, writer);

        if (hasObjectNumber()) {
            writer.write("\nendobj\n");
        }
       
        writer.flush();
        return cout.getCount();
    }
View Full Code Here

        this.idRef = idRef;
    }

    /** {@inheritDoc} */
    protected int output(OutputStream stream) throws IOException {
        CountingOutputStream cout = new CountingOutputStream(stream);
        Writer writer = PDFDocument.getWriterFor(cout);
       
        formatObject(getIDRef(), cout, writer);
        writer.write(' ');
        formatObject(goToReference, cout, writer);
       
        writer.flush();
        return cout.getCount();
    }
View Full Code Here

        return this.name;
    }

    /** {@inheritDoc} */
    protected int output(OutputStream stream) throws IOException {
        CountingOutputStream cout = new CountingOutputStream(stream);
        Writer writer = PDFDocument.getWriterFor(cout);
        if (hasObjectNumber()) {
            writer.write(getObjectID());
        }

        writer.write(toString());
       
        if (hasObjectNumber()) {
            writer.write("\nendobj\n");
        }
       
        writer.flush();
        return cout.getCount();
    }
View Full Code Here

        this.values.add(new Double(value));
    }
   
    /** {@inheritDoc} */
    protected int output(OutputStream stream) throws IOException {
        CountingOutputStream cout = new CountingOutputStream(stream);
        Writer writer = PDFDocument.getWriterFor(cout);
        if (hasObjectNumber()) {
            writer.write(getObjectID());
        }
       
        writer.write('[');
        for (int i = 0; i < values.size(); i++) {
            if (i > 0) {
                writer.write(' ');
            }
            Object obj = this.values.get(i);
            formatObject(obj, cout, writer);
        }
        writer.write(']');
       
        if (hasObjectNumber()) {
            writer.write("\nendobj\n");
        }
       
        writer.flush();
        return cout.getCount();
    }
View Full Code Here

                    out = new NullOutputStream();
                } else {
                    out = new java.io.FileOutputStream(outfile);
                    out = new java.io.BufferedOutputStream(out);
                }
                CountingOutputStream cout = new CountingOutputStream(out);
                try {
                    Source src;
                    Templates templates;

                    if (def.getFO() != null) {
                        src = new StreamSource(new File(def.getFO()));
                        templates = null;
                    } else {
                        src = new StreamSource(new File(def.getXML()));
                        templates = def.getTemplates();
                    }
                    fop.process(src, templates, cout);
                } finally {
                    IOUtils.closeQuietly(cout);
                }
                results.add(new Result(def, start, System.currentTimeMillis(),
                        cout.getByteCount()));
            } catch (Exception e) {
                results.add(new Result(def, start, System.currentTimeMillis(), e));
                throw e;
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.io.output.CountingOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.