|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
com.antelmann.io.InterceptInputStream
public class InterceptInputStream
A specialized stream that allows to provide custom actions upon the occurrence of a given byte pattern. The custom actions occur through registered Handler objects; bytes can be skipped from the stream (to not have the given pattern occur in the stream) and bytes can be inserted into the stream through given methods. The class may be subclassed to provide more sophisticated pattern matching, as this implementation only acts upon exact matches of a search pattern found.
ReplaceInputStream| Nested Class Summary | |
|---|---|
static interface |
InterceptInputStream.Handler
used to handle pattern occurrences for an InterceptInputStream |
| Constructor Summary | |
|---|---|
InterceptInputStream(InputStream in,
byte[] searchPattern)
|
|
| Method Summary | |
|---|---|
void |
addHandler(InterceptInputStream.Handler handler)
|
protected int |
checkForMatch(byte[] buffer1,
byte[] buffer2,
byte[] searchPattern,
int cursor)
checks whether the exact searchPattern can be found in buffer1 or in the intersection between buffer1 and buffer2. |
void |
close()
|
void |
insertBytes(byte[] bytes)
inserts the given bytes into the stream, so that these bytes are read next before all others that would normally follow at this point. |
boolean |
markSupported()
returns false |
int |
read()
|
long |
readSoFar()
returns the total number of bytes read from the original stream so far (not considering inserted bytes but counting skipped bytes) |
void |
reset()
throws IOException |
long |
skip(long numberOfBytes)
skips bytes only from the source input stream - ignoring inserted bytes |
| Methods inherited from class java.io.InputStream |
|---|
available, mark, read, read |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public InterceptInputStream(InputStream in,
byte[] searchPattern)
| Method Detail |
|---|
public void addHandler(InterceptInputStream.Handler handler)
public void close()
throws IOException
close in interface Closeableclose in class InputStreamIOExceptionpublic boolean markSupported()
markSupported in class InputStream
public void reset()
throws IOException
reset in class InputStreamIOExceptionpublic void insertBytes(byte[] bytes)
public long skip(long numberOfBytes)
throws IOException
skip in class InputStreamIOException
public int read()
throws IOException
read in class InputStreamIOExceptionpublic long readSoFar()
protected int checkForMatch(byte[] buffer1,
byte[] buffer2,
byte[] searchPattern,
int cursor)
buffer1 - byte array containing the current stream bufferbuffer2 - byte array containing the following buffer
(to enable pattern search in intersections of two buffers,
so that all occurences within the stream can be found)searchPattern - the pattern that is used for the pattern matchingcursor - the current position of the stream within buffer1
Data.indexOf(byte[], byte[], int, int),
(byte[], byte[], byte[])
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||