|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectthings.thinger.io.StreamSourceFromStreamStalled
public class StreamSourceFromStreamStalled
A character stream source. It will tee a single character, so be sure the underlying stream will starve it (pass EOF) if it should cross a barrier and read something it isn't allowed to have. See the HeaderProcessor for an example of how to do this.
I had to add this one to deal with socket streams, where you don't really know if you are at the end or not. It will treat no available bytes the same as EOF. This means it is somewhat sensitive to truncation on slow pipes. There is a slight delay given if the available count is 0 just to see if something shows up.
I really upped the delays, because network connections can seriously lag. It's a pain. The initial delay will always be way longer than subsequent reads.
Why not use timeouts, you ask? We really don't know what kind of stream we are getting. In all, a proper implementation would probably deal directly with the channels and leave the layers stream abstractions out of it. Since this is just a tool, I'm not going to bother. Unfortunately, it makes the mini-http server a little slow.
Version History
EPG - Initial (toolkit) - 7 SEP 03 EPG - Played with the delays - 10 MAY 07
Field Summary | |
---|---|
static int |
INIT_STALL_PERIOD
This is the stall period in millis for the initialization. |
static int |
INIT_STALL_RAMP
This is how much we increase the stall period for every iteration. |
static int |
MAX_INIT_STALL
Maximum stall period for the initialization. |
static int |
STALL_PERIOD
This is the stall period in millis. |
static int |
STALL_RETRIES
Maximum stall period for the initialization. |
Constructor Summary | |
---|---|
StreamSourceFromStreamStalled()
A null constructor. |
|
StreamSourceFromStreamStalled(java.io.InputStream source)
Constructor. |
Method Summary | |
---|---|
int |
available()
It'll try a few times until something is available or it runs out of time. |
boolean |
hasMore()
Does the source have more to get? |
int |
next()
Get the next character. |
void |
reuse(java.io.InputStream source)
Reuse this object but with another stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int INIT_STALL_PERIOD
public static final int INIT_STALL_RAMP
public static final int MAX_INIT_STALL
public static final int STALL_PERIOD
public static final int STALL_RETRIES
Constructor Detail |
---|
public StreamSourceFromStreamStalled()
public StreamSourceFromStreamStalled(java.io.InputStream source) throws java.lang.Throwable
source
- the input stream source.
java.lang.Throwable
Method Detail |
---|
public void reuse(java.io.InputStream source) throws java.lang.Throwable
source
- The input stream source.
java.lang.Exception
java.lang.Throwable
public int next() throws java.lang.Exception
This treats the available < 0 as EOF.
next
in interface StreamSource
java.lang.Exception
public int available() throws java.lang.Exception
java.lang.Exception
public boolean hasMore() throws java.lang.Exception
hasMore
in interface StreamSource
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |