public class DelayedOutputStream extends OutputStream implements TickListener, DelayShaper
OutputStream instance with a delay real the transferred
bytes.
The stream uses a TickSource as a source of timing information and
delays the sending of data by a certain number of ticks.| Constructor and Description |
|---|
DelayedOutputStream(TickSource t,
OutputStream real,
long delay,
int bufferSize)
Constructs a new
DelayedOutputStream with the given parameters. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
OutputStream |
getBaseStream()
Returns the underlying
InputStream. |
int |
getBufferSize()
Returns the buffer size, real bytes
|
long |
getDelay()
Returns the current delay in ticks.
|
TickSource |
getTickSource()
Returns the
TickSource this stream uses. |
void |
setDelay(long delay)
Sets a new delay in ticks.
|
void |
tick(long tick)
Called when a tick event is fired.
|
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
flushpublic DelayedOutputStream(TickSource t, OutputStream real, long delay, int bufferSize)
DelayedOutputStream with the given parameters.t - The tick source to usereal - The underlying InputStream to read data fromdelay - The delay (real ticks) to introduce to databufferSize - The buffer size to use. The implementation has to store read
bytes real an intermediate buffer. The buffer must be large
enough to store the data. Note that data which cannot be stored
into the buffer because of its overflow will have a higher
delay, which is why the buffer should be significantly higher
than the expected data arrivel rate (times the expected interval
of reading from this stream).public void write(int b)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamIOExceptionpublic void tick(long tick)
TickListenerLong.MAX_VALUE is followed by
Long.MIN_VALUE.
Furthermore, it is guaranteed that ticks do not overlap each other, ie. no
two threads will enter the same object's TickListener.tick(long)
at the same time.tick in interface TickListenertick - the tick numberpublic void write(byte[] b)
throws IOException
write in class OutputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOExceptionpublic void setDelay(long delay)
DelayShapersetDelay in interface DelayShaperdelay - the new delay in tickspublic long getDelay()
DelayShapergetDelay in interface DelayShaperpublic int getBufferSize()
public OutputStream getBaseStream()
InputStream.public TickSource getTickSource()
TickSource this stream uses.Copyright © 2015. All rights reserved.