com.gc.iotools.stream.writer.inspection
Class StatsWriter

java.lang.Object
  extended by java.io.Writer
      extended by com.gc.iotools.stream.writer.inspection.StatsWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class StatsWriter
extends Writer

A delegating Writer that gather statistics on the Writer passed in the constructor.

It can be used to read:

Full statistics are available after the stream has been fully processed (by other parts of the application), or after invoking the method close() while partial statistics are available on the fly.

Since:
1.2.14
Version:
$Id: StatsWriter.java 527 2014-02-24 19:29:50Z gabriele.contini@gmail.com $
Author:
Gabriele Contini

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
StatsWriter(Writer destination)
          Creates a new StatsWriter with the given destination character stream.
 
Method Summary
 void close()
          
 void flush()
          
 String getBitRateString()
           Returns a string representation of the writing bit rate formatted with a convenient unit.
 long getSize()
          Returns the number of characters written until now.
 long getTime(TimeUnit tu)
           Returns the time spent waiting for the internal stream to write the data.
 void write(char[] b)
          
 void write(char[] b, int off, int len)
          
 void write(int b)
          
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatsWriter

public StatsWriter(Writer destination)
Creates a new StatsWriter with the given destination character stream.

Parameters:
destination - Destination stream where data are written.
Method Detail

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException

flush

public void flush()
           throws IOException

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

getBitRateString

public String getBitRateString()

Returns a string representation of the writing bit rate formatted with a convenient unit. The unit will change trying to keep not more than 3 digits.

Returns:
The characterRate of the stream.

getSize

public long getSize()
Returns the number of characters written until now.

Returns:
return the number of characters written until now.

getTime

public long getTime(TimeUnit tu)

Returns the time spent waiting for the internal stream to write the data.

Parameters:
tu - Unit to measure the time.
Returns:
time spent in waiting.

write

public void write(char[] b)
           throws IOException

Overrides:
write in class Writer
Throws:
IOException

write

public void write(char[] b,
                  int off,
                  int len)
           throws IOException

Specified by:
write in class Writer
Throws:
IOException

write

public void write(int b)
           throws IOException

Overrides:
write in class Writer
Throws:
IOException


Copyright © 2008–2014. All rights reserved.