|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.InputStream | +--java.io.FilterInputStream | +--gausssoft.io.StatusInputStream | +--gausssoft.io.ChunkingInputStream | +--gausssoft.io.BandwidthInputStream | +--gausssoft.io.BandwidthControlledInputStream
This class restricts the level of throughput that flows to an underlying InputStream
.
This implementation uses the ChunkingInputStream
class to perform updates.
It is recommended that you look at how the ChunkingInputStream
class
works before using this class.
This class lets a certain amount of bytes pass to the underlying stream (which can be set at
construction time and also by the ChunkingInputStream.setChunkSize(int)
method). After
this amount of bytes pass through the stream, it is calculated if bandwidth has been exceeded.
If it has, the method will pause to average the bandwidth out.
The lower the chunk size, the more method overhead that will be generated, as well as any inefficiency by reading in data in small chunks. The higher the chunk size, the less method overhead, as well as being more efficient by reading in data in bigger chunks, however, this results in more of a burst-stop effect.
For example, if you have a very restrictive bandwidth on a stream which is very fast, and you set the chunk size to a very large size, initial reads will occur at the normal stream speed, disregarding the bandwidth limit. When a check is enforced, it will pause for a long while to average out the bandwidth. Although this "burst-stop" effect will happen whatever chunk size you specify, throughput will be much more consistent if it is set for lower values.
You can also specify if bandwidth restrictions should still apply at the end of the stream. For example, say you have a stream containing 2000 bytes, and you have a chunk size of 1500. An initial read of 1250 is performed, followed by 250 bytes (which will force a bandwidth check). You now have 500 bytes left. You attempt to read another 1000 bytes, but only 500 bytes are left, so 500 bytes are returned. This then leaves 500 bytes that have not been checked. You can specify whether these bytes should be subject to bandwidth checks as well.
BandwidthControlledOutputStream
,
BandwidthInputStream
Fields inherited from class java.io.FilterInputStream |
in |
Constructor Summary | |
BandwidthControlledInputStream(InputStream in,
int bps)
Creates a new BandwidthControlledInputStream using a chunk size of 1024 bytes that does not perform end of stream checks. |
|
BandwidthControlledInputStream(InputStream in,
int bps,
int chunksize)
Creates a new BandwidthControlledInputStream that does not perform end of stream checks. |
|
BandwidthControlledInputStream(InputStream in,
int bps,
int chunksize,
boolean end)
Creates a new BandwidthControlledInputStream. |
Method Summary | |
protected void |
forceCheck()
Forces any unchecked bytes that have passed to the underlying stream to be checked immediately (and for bandwidth to be averaged out). |
int |
getLimit()
Returns the current bandwidth limit. |
void |
initiate()
Begins measuring and restricting bandwidth to the underlying InputStream. |
protected void |
interrupt()
Used for enforcing bandwidth checks. |
boolean |
isLimiting()
Returns true if this object is restricting bandwidth. |
void |
setLimit(int bps)
Sets a new bandwidth limit. |
void |
setLimiting(boolean active)
Enables / disables the limiting of throughput on this object. |
Methods inherited from class gausssoft.io.BandwidthInputStream |
close, getBandwidth, initiated, resetMeasuring |
Methods inherited from class gausssoft.io.ChunkingInputStream |
getChunkSize, read, read, read, setChunkSize, skip, updateChunkSize |
Methods inherited from class gausssoft.io.StatusInputStream |
available, getCount, isClosed, isEmpty |
Methods inherited from class java.io.FilterInputStream |
mark, markSupported, reset |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public BandwidthControlledInputStream(InputStream in, int bps)
in
- The InputStream to wrap around.bps
- The bandwidth to limit the stream to.NullPointerException
- If in
is null
.IllegalArgumentException
- If bps
is less than 1.public BandwidthControlledInputStream(InputStream in, int bps, int chunksize)
in
- The InputStream to wrap around.bps
- The bandwidth to limit the stream to.chunksize
- The chunk size to use.NullPointerException
- If in
is null
.IllegalArgumentException
- If bps
or chunksize
is less than 1.public BandwidthControlledInputStream(InputStream in, int bps, int chunksize, boolean end)
in
- The InputStream to wrap around.bps
- The bandwidth to limit the stream to.chunksize
- The chunk size to use.end
- true
if bandwidth should still be adjusted at the end of a stream.NullPointerException
- If in
is null
.IllegalArgumentException
- If bps
or chunksize
is less than 1.Method Detail |
public void initiate()
initiate
in class BandwidthInputStream
BandwidthInputStream.initiated()
public final boolean isLimiting()
true
if this object is restricting bandwidth.true
if this object is restricting bandwidth.public final void setLimiting(boolean active)
active
- true
if this object should begin limiting throughput.public final int getLimit()
public final void setLimit(int bps)
bps
- The new bandwidth limit.IllegalArgumentException
- If bps
is less than 1.protected void interrupt()
interrupt
in class BandwidthInputStream
ChunkingInputStream.interrupt()
,
forceCheck()
protected final void forceCheck()
Note: This method must be called only when no IO operations are currently taking place. Invoking this method will use the current bandwidth limit and activity setting. Any new values which have yet to be stored in the variables will not be used.
interrupt()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |