|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream org.freehep.util.io.RoutedInputStream
public class RoutedInputStream
The RoutedInputStream allows the user to add a listener for a certain delimited portion of the main inputstream. This portion is marked by a start and end marker. The end marker can be null, in which case the portion runs from the start marker to the end of the main inputstream. The listener is informed via a route (partial inputstream) when input is available. The new routed inputstream (route) is supposed to be read to the end or closed, after which the main inputstream should be read again. Closing a route will not close the original stream, but will discard any bytes up to and including the end marker. Returning from a route without reading until the end of the route means that the remaining bytes are still available on the main stream. Multiple routes can be added, as long as they have different start sequences. Start sequences such as "StartA, StartB, StartEmpty" are allowed, but "Start, StartOther" are not since they overlap. Start and End markers can be the same. IMPORTANT: inherits from InputStream rather than FilterInputStream so that the correct read(byte[], int, int) method is used.
Nested Class Summary | |
---|---|
class |
RoutedInputStream.Route
Route which can be read up to and including the end marker. |
Constructor Summary | |
---|---|
RoutedInputStream(InputStream input)
Creates a RoutedInputStream from the underlying stream. |
Method Summary | |
---|---|
void |
addRoute(byte[] start,
byte[] end,
RouteListener listener)
Adds a route for given start and end marker. |
void |
addRoute(String start,
String end,
RouteListener listener)
Adds a route for given start and end string. |
int |
read()
Returns the next byte on this stream, however if a start marker is found, the associated route listener is called, which should take over reading the stream. |
Methods inherited from class java.io.InputStream |
---|
available, close, mark, markSupported, read, read, reset, skip |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RoutedInputStream(InputStream input)
input
- stream to readMethod Detail |
---|
public int read() throws IOException
read
in class InputStream
IOException
public void addRoute(String start, String end, RouteListener listener)
start
- start markerend
- end markerlistener
- listener to inform about the routepublic void addRoute(byte[] start, byte[] end, RouteListener listener)
start
- start markerend
- end markerlistener
- listener to inform about the route
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |