|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
com.limegroup.gnutella.util.ThrottledOutputStream
Wraps a stream to ensure that the caller can write no more than N bytes/sec. ThrottledOutputStream delegates to a BandwidthThrottle object to control throughput. By sharing a single BandwidthThrottle among multiple ThrottledOutputStream instances, the user can approximate fair global bandwidth sharing.
This implementation is based on the ThrottledOutputStream class from the Freenet project. It has been modified so that the bandwidth throttle is no longer static. It also no longer subclasses FilterOutputStream, as the temptation to call super.write() introduced some bugs.
Constructor Summary | |
ThrottledOutputStream(java.io.OutputStream delegate,
BandwidthThrottle throttle)
Wraps the delegate stream with the given throttle. |
Method Summary | |
void |
close()
|
void |
flush()
|
void |
write(byte[] data)
Write the given bytes to the delegate stream, possibly blocking if necessary to ensure that throughput doesn't exceed the limits. |
void |
write(byte[] data,
int offset,
int totalLength)
Write bytes[offset...offset+totalLength-1] to the delegate stream, possibly blocking if necessary to ensure that throughput doesn't exceed the limits. |
void |
write(int b)
Write a single byte to the delegate stream, possibly blocking if necessary to ensure that throughput doesn't exceed the limits. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ThrottledOutputStream(java.io.OutputStream delegate, BandwidthThrottle throttle)
delegate
- the underlying stream for all IOthrottle
- limits throughput. May be shared with other streams.Method Detail |
public void write(int b) throws java.io.IOException
b
- the byte to write.
java.io.IOException
- if an I/O error occurs on the OutputStream.public void write(byte[] data, int offset, int totalLength) throws java.io.IOException
data
- the bytes to write.offset
- the index in the array to start at.totalLength
- the number of bytes to write.
java.io.IOException
- if an I/O error occurs on the OutputStream.public void write(byte[] data) throws java.io.IOException
java.io.IOException
public void flush() throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |