com.mucommander.io
Class ByteCounter

java.lang.Object
  extended by com.mucommander.io.ByteCounter

public class ByteCounter
extends java.lang.Object

Contains a number of bytes which have been read/written from/to a CounterInputStream/CounterOutputStream.

Provided methods allow to read the the byte count, add a number bytes to it or reset it (make it zero).

This class is thread safe, ensuring that the counter is always in a consistent state.

Author:
Maxence Bernard
See Also:
CounterInputStream, CounterOutputStream

Constructor Summary
ByteCounter()
          Creates a new ByteCounter with an initial byte count equal to zero.
ByteCounter(ByteCounter counter)
          Creates a new ByteCounter with an initial byte count equal to zero and using the given ByteCounter.
 
Method Summary
 void add(ByteCounter counter, boolean resetAfter)
          Increases the byte counter by the number of bytes contained in the specified counter (as returned by its getByteCount() method) and resets its byte counter after (if specified).
 void add(long nbBytes)
          Increases the byte counter by the provided number of bytes.
 long getByteCount()
          Return the number of bytes which have been accounted for.
 void reset()
          Resets the byte counter (make it zero).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteCounter

public ByteCounter()
Creates a new ByteCounter with an initial byte count equal to zero.


ByteCounter

public ByteCounter(ByteCounter counter)
Creates a new ByteCounter with an initial byte count equal to zero and using the given ByteCounter.

The value returned by getByteCount() will be the sum of the internal byte count and the one from the specified ByteCounter, as returned by its getByteCount() method. Resetting this ByteCounter's value will only affect the internal byte count and not the one from the specified ByteCounter.

Method Detail

getByteCount

public long getByteCount()
Return the number of bytes which have been accounted for.


add

public void add(long nbBytes)
Increases the byte counter by the provided number of bytes. If the specified number is negative, the byte counter will be left unchanged (won't be decreased).

Parameters:
nbBytes - number of bytes to add to the byte counter, will be ignored if negative

add

public void add(ByteCounter counter,
                boolean resetAfter)
Increases the byte counter by the number of bytes contained in the specified counter (as returned by its getByteCount() method) and resets its byte counter after (if specified).

Parameters:
counter - the Bytecounter to add to this one, and reset after (if specified).
resetAfter - if true, the specified counter will be reset after its byte count has been added to this ByteCounter

reset

public void reset()
Resets the byte counter (make it zero).



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