|
EAF 7.4 Implementation | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
com.lutris.util.BMByteSearchStream
public class BMByteSearchStream
Implements the Boyer-Moore pattern matching algorithm for a given byte pattern. This object implements searches on byte-oriented input streams.
The algorithm was obtained from "Computer Algorithms - Introduction to Design and Analysis, Second Edition" by Sara Baase.
Field Summary | |
---|---|
static int |
AT_PATTERN
"At Pattern" value. |
static int |
EOF
EOF value. |
Fields inherited from class java.io.FilterInputStream |
---|
in |
Constructor Summary | |
---|---|
BMByteSearchStream(java.io.InputStream inputSource,
java.lang.String pattern,
int buflen)
Creates a Boyer-Moore byte stream scanner for a given pattern. |
Method Summary | |
---|---|
int |
available()
Returns the number of bytes that can be read from this input stream without blocking. |
int |
availableTo()
Returns the number of bytes that can be read from this input stream without blocking or encountering the search pattern. |
java.lang.String |
peekAheadString(int length)
Returns the next length bytes of the input buffer
as a string. |
int |
read()
Reads the next byte of data from this input stream. |
int |
read(byte[] buffer)
Reads up to buffer.length bytes of data from this input
stream into an array of bytes. |
int |
read(byte[] buffer,
int offset,
int length)
Reads length bytes of data from this input stream into
an array of bytes. |
int |
readTo(byte[] buffer,
int offset,
int length)
Reads data into a buffer until the search pattern or the end of file is detected. |
void |
setPattern(BMByteSearch search)
Set the search pattern. |
void |
setPattern(java.lang.String pattern)
Set the search pattern. |
long |
skip(long n)
Skips over and discards n bytes of data from the input stream. |
int |
skipPattern()
Skips all bytes up to and including the search pattern or EOF. |
int |
skipTo()
Skips all bytes up to but not including the search pattern or EOF. |
Methods inherited from class java.io.FilterInputStream |
---|
close, mark, markSupported, reset |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int EOF
public static final int AT_PATTERN
Constructor Detail |
---|
public BMByteSearchStream(java.io.InputStream inputSource, java.lang.String pattern, int buflen)
buflen
for the scanning
buffer.
inputSource
- The input source stream to scan.pattern
- The pattern to scan for. Characters
outside the Latin-1 encoding are truncated
to signed bytes.buflen
- The length to use for the scanning buffer.Method Detail |
---|
public int read() throws java.io.IOException
int
in the range 0 to 255. If no
byte is available because the end of the stream has been reached,
the value -1 is returned. This method blocks until input data is
available, the end of the stream is detected, or an exception is
thrown
read
in class java.io.FilterInputStream
java.io.IOException
- If an I/O error occurs.public int read(byte[] buffer) throws java.io.IOException
buffer.length
bytes of data from this input
stream into an array of bytes. This method blocks until some input
is available
read
in class java.io.FilterInputStream
buffer
- The buffer into which data are read.
java.io.IOException
- If an I/O error occurs.public int read(byte[] buffer, int offset, int length) throws java.io.IOException
length
bytes of data from this input stream into
an array of bytes. This method blocks until some input is available.
read
in class java.io.FilterInputStream
buffer
- The buffer into which data are read.offset
- The start offset of the data.length
- The maximum number of bytes read.
java.io.IOException
- If an I/O error occurs.public long skip(long n) throws java.io.IOException
skip
method may, for a variety of reasons,
end up skipping over some smaller number of bytes, possibly 0.
The actual number of bytes skipped is returned.
skip
in class java.io.FilterInputStream
n
- The number of bytes to be skipped.
java.io.IOException
- If an I/O error occurs.public int available() throws java.io.IOException
available
method.
available
in class java.io.FilterInputStream
java.io.IOException
- If an I/O error occurs.public int availableTo() throws java.io.IOException
java.io.IOException
- If an I/O error occurs.public int readTo(byte[] buffer, int offset, int length) throws java.io.IOException
-1
if at the
search pattern or end-of-file.
buffer
- Buffer to read into.offset
- Offset in buffer to read into.length
- Number of bytes to try to read.
-1
if at the pattern or eof.
java.io.IOException
- Thrown if an I/O exception occurs.public int skipTo() throws java.io.IOException
java.io.IOException
- Thrown if an I/O exception occurs.public int skipPattern() throws java.io.IOException
java.io.IOException
- Thrown if an I/O exception occurs.public void setPattern(java.lang.String pattern)
pattern
- The new pattern to search for.public void setPattern(BMByteSearch search)
search
- The precomputed Boyer-Moore searcher.public java.lang.String peekAheadString(int length) throws java.io.IOException
length
bytes of the input buffer
as a string. If fewer than length
bytes remain on
the input stream, then only the remaining bytes are returned. If
the input stream is at EOF and there are no more bytes in the buffer
then an empty string is returned.
length
- The number of bytes to look ahead.
java.io.IOException
- Thrown if an I/O exception occurs.
|
EAF 7.4 Implementation | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |