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

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

Introduction

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

Prototype

public void write(int b) throws IOException 

Source Link

Document

Writes a single byte to the output stream adding to the count of the number of bytes written.

Usage

From source file:com.discursive.jccook.io.CountingOutExample.java

public void start() {

    File test = new File("test.dat");
    CountingOutputStream countStream = null;

    try {//  w  ww. j  a  v  a2s. c  o  m
        FileOutputStream fos = new FileOutputStream(test);
        countStream = new CountingOutputStream(fos);
        countStream.write("Hello".getBytes());
    } catch (IOException ioe) {
        System.out.println("Error writing bytes to file.");
    } finally {
        IOUtils.closeQuietly(countStream);
    }

    if (countStream != null) {
        int bytesWritten = countStream.getCount();
        System.out.println("Wrote " + bytesWritten + " bytes to test.dat");
    }

}