Example usage for org.apache.commons.io.output CountingOutputStream resetCount

List of usage examples for org.apache.commons.io.output CountingOutputStream resetCount

Introduction

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

Prototype

public synchronized int resetCount() 

Source Link

Document

Set the byte count back to 0.

Usage

From source file:org.shaman.database.Benchmark.java

/**
 * prints the file size//from   w ww .j  a  v  a  2 s  . c o  m
 * @param roots the roots from the different passes
 */
private void printFileSizes(Record... roots) throws IOException {
    //result array
    int size;

    String format = "%1$,11d";
    System.out.println("passes       database          serial      compressed             xml");

    //save it
    for (int i = 0; i < roots.length; i++) {
        Record root = roots[i];
        System.out.print("pass " + (i + 1) + "   ");
        //database
        ArrayOutput ao = new ArrayOutput();
        Database db = new Database(root);
        db.save(ao, FailOnErrorHandler.INSTANCE);
        size = ao.getTotalSize();
        System.out.printf(format, size);
        System.out.print("B    ");

        //uncompressed serialization
        CountingOutputStream out = new CountingOutputStream(new NullOutputStream());
        ObjectOutputStream dos = new ObjectOutputStream(out);
        dos.writeObject(root);
        dos.flush();
        size = out.getCount();
        System.out.printf(format, size);
        System.out.print("B    ");

        //compressed serialization
        out.resetCount();
        dos = new ObjectOutputStream(new GZIPOutputStream(out));
        dos.writeObject(root);
        dos.flush();
        size = out.getCount();
        System.out.printf(format, size);
        System.out.print("B    ");

        //xml
        out.resetCount();
        XMLEncoder xml = new XMLEncoder(out);
        xml.writeObject(root);
        xml.flush();
        size = out.getCount();
        System.out.printf(format, size);
        System.out.println("B");
    }

}