|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.InputStream
com.mucommander.io.ThroughputLimitInputStream
public class ThroughputLimitInputStream
ThroughputLimitInputStream extends InputStream to provide control over the transfer speed and limit it to a specified number of bytes per second. Whenever the bytes per second quota has been reached, the read and skip methods will lock and won't return until either:
setThroughputLimit(long) is called with a more permissive bytes per second value (different from 0),
yielding to more bytes available for the current second.
Setting the throughput limit to 0 effectively blocks all read and skip calls indefinitely.
Any calls to the read or skip methods will lock, the only way to remove this lock being to call the
setThroughputLimit(long) method with a value different from 0 from another thread.
Setting the throughput limit to -1 or any other negative values will disable any limit and make this ThroughputLimitInputStream behave just like a normal InputStream.
Finally, the setUnderlyingInputStream(java.io.InputStream) method allows to use the
same ThroughputLimitInputStream instance for multiple InputStream instances, keeping the bytes count for the
current second intact and thus the throughput limit stable. This does not hold true if a new ThroughputLimitInputStream
is created for each InputStream, the bytes count for the current second starting at 0.
| Constructor Summary | |
|---|---|
ThroughputLimitInputStream(java.io.InputStream in)
Creates a new ThroughputLimitInputStream with no initial throughput limit (-1 value). |
|
ThroughputLimitInputStream(java.io.InputStream in,
long bytesPerSecond)
Creates a new ThroughputLimitInputStream with an initial throughput limit. |
|
| Method Summary | |
|---|---|
int |
available()
|
void |
close()
|
void |
mark(int i)
|
boolean |
markSupported()
|
int |
read()
|
int |
read(byte[] bytes)
|
int |
read(byte[] bytes,
int off,
int len)
|
void |
reset()
|
void |
setThroughputLimit(long bytesPerSecond)
Specifies a new throughput limit expressed in bytes per second. |
void |
setUnderlyingInputStream(java.io.InputStream in)
Changes the underlying InputStream which data is read from, keeping the bytes count for the current second intact. |
long |
skip(long l)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ThroughputLimitInputStream(java.io.InputStream in)
in - underlying stream that is used to read data frompublic ThroughputLimitInputStream(java.io.InputStream in, long bytesPerSecond)
in - underlying stream that is used to read data frombytesPerSecond - initial throughput limit in bytes per secondsetThroughputLimit(long)| Method Detail |
|---|
public void setThroughputLimit(long bytesPerSecond)
Setting the throughput limit to 0 effectively blocks all read and skip calls indefinitely.
Any calls to the read or skip methods will lock, the only way to remove this lock being to call the
setThroughputLimit(long) method with a value different from 0 from another thread.
Setting the throughput limit to -1 or any other negative values will disable any limit and make this ThroughputLimitInputStream behave just like a normal InputStream.
bytesPerSecond - new throughput limit expressed in bytes, -1 to disable it, 0 to block reads.public void setUnderlyingInputStream(java.io.InputStream in)
Note: the existing underlying InputStream will not be closed, the close() method must be called prior
to calling this method.
in - the new InputStream to read data frompublic int read() throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] bytes) throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] bytes, int off, int len) throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic long skip(long l) throws java.io.IOException
skip in class java.io.InputStreamjava.io.IOExceptionpublic int available() throws java.io.IOException
available in class java.io.InputStreamjava.io.IOExceptionpublic void close() throws java.io.IOException
close in interface java.io.Closeableclose in class java.io.InputStreamjava.io.IOExceptionpublic void mark(int i)
mark in class java.io.InputStreampublic void reset() throws java.io.IOException
reset in class java.io.InputStreamjava.io.IOExceptionpublic boolean markSupported()
markSupported in class java.io.InputStream
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard