com.mucommander.io
Class CounterOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.mucommander.io.CounterOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class CounterOutputStream
extends java.io.OutputStream

An OutputStream that keeps track of the number of bytes that have been written to it.

The actual number of bytes can be retrieved from the ByteCounter instance returned by getCounter(). The CounterOutputStream(OutputStream, ByteCounter) constructor can be used to specify an existing ByteCounter instance instead of creating a new one. The ByteCounter will always remain accessible, even after this stream has been closed.

Author:
Maxence Bernard
See Also:
ByteCounter

Constructor Summary
CounterOutputStream(java.io.OutputStream out)
          Creates a new CounterOutputStream using the specified OutputStream.
CounterOutputStream(java.io.OutputStream out, ByteCounter counter)
          Creates a new CounterOutputStream using the specified OutputStream and ByteCounter.
 
Method Summary
 void close()
           
 void flush()
           
 ByteCounter getCounter()
          Returns the ByteCounter that holds the number of bytes that have been written to this OutputStream.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CounterOutputStream

public CounterOutputStream(java.io.OutputStream out)
Creates a new CounterOutputStream using the specified OutputStream. A new ByteCounter will be created.

Parameters:
out - the underlying OutputStream the data will be written to

CounterOutputStream

public CounterOutputStream(java.io.OutputStream out,
                           ByteCounter counter)
Creates a new CounterOutputStream using the specified OutputStream and ByteCounter. The provided ByteCounter will NOT be reset, whatever value it contains will be kept.

Parameters:
out - the underlying OutputStream the data will be written to
Method Detail

getCounter

public ByteCounter getCounter()
Returns the ByteCounter that holds the number of bytes that have been written to this OutputStream.


write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard