org.jumpmind.symmetric.util
Class MeteredOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by org.jumpmind.symmetric.util.MeteredOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class MeteredOutputStream
extends java.io.FilterOutputStream

Throttle output stream to write at a specified rate. the rate will be an average

Author:
hwang

Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
MeteredOutputStream(java.io.OutputStream out, long maxBps)
           
MeteredOutputStream(java.io.OutputStream out, long maxBps, long threshold)
           
MeteredOutputStream(java.io.OutputStream out, long maxBps, long threshold, long checkPoint)
           
 
Method Summary
 void write(int b)
           
 
Methods inherited from class java.io.FilterOutputStream
close, flush, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MeteredOutputStream

public MeteredOutputStream(java.io.OutputStream out,
                           long maxBps,
                           long threshold)
Parameters:
out - stream written to
maxBps - max number of bytes per second
threshold - the number in bytes before the throttle output stream

MeteredOutputStream

public MeteredOutputStream(java.io.OutputStream out,
                           long maxBps,
                           long threshold,
                           long checkPoint)
Parameters:
out - out stream written to
maxBps - max number of bytes per second
threshold - the number in bytes before throttling output stream
checkPoint - check the average rate when total byts%checkPoint == 0.
the throttled output stream will write checkPoing number of bytes at full speed, and then sleep for a certain to obtain an average close to maxBps. If set it to 1, it will check every bytes written and the rate will be the most accurate.

MeteredOutputStream

public MeteredOutputStream(java.io.OutputStream out,
                           long maxBps)
Parameters:
out -
maxBps -
Method Detail

write

public void write(int b)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream
Throws:
java.io.IOException


Copyright © 2007-2008. All Rights Reserved.