|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.foray.common.ByteSequenceSearcher
public final class ByteSequenceSearcher
For illustration purposes, consider the file to be a sequence of bytes ordered from left to right. The goal here is to create an array that acts like a "viewbox" on the contents of the file. We will slide the viewbox over the contents of the file to see it. (We slide the box in big chunks to minimize the cost of i/o operations. If performance were not an issue, we could just read the file one byte at a time). If we are reading the file forward, we will be sliding the right end of the viewbox over the left end of the file. If we are reading the file backward, we will be sliding the left end of the viewbox over the right end of the file. Searches binary (or text) files for the specified contents in a relatively efficient manner. The two extreme approaches are as follows: 1) Read the entire file into a byte array and search that array. This can use quite a bit of memory. 2) Read one byte at a time. This doesn't use much memory, but can be very slow. Instead of either of these approaches, searchBytes strikes a middle ground in which an intermediate amount of memory is read and searched. Please note that searchBytes is looking for bytes that match, not characters that match.
Method Summary | |
---|---|
static boolean |
byteArrayCompare(byte[] bytesToSearch,
int bytesToSearchOffset,
byte[] bytesToFind)
Determine if the contents of bytesToFind is equal to the contents of bytesToSearch at a given location. |
long |
searchBytes()
Searches the content for the sought byte sequence. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public long searchBytes() throws IOException
IOException
- For errors reading the file.public static boolean byteArrayCompare(byte[] bytesToSearch, int bytesToSearchOffset, byte[] bytesToFind)
bytesToSearch
- The (bigger) byte array that is being searched.bytesToSearchOffset
- The location in bytesToSearch at which to
start the comparison.bytesToFind
- The (smaller) byte array that contains the content
to be matched in bytesToSearch.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |