Class ByteSearch
- java.lang.Object
-
- org.apache.axiom.attachments.utils.ByteSearch
-
public class ByteSearch extends Object
ByteSearch Various byte array searching utilities. This includes a "skip search", which is a an optimized search for finding a byte pattern in a large byte array.- Author:
- Richard Scheuerle (scheu@us.ibm.com)
-
-
Constructor Summary
Constructors Constructor Description ByteSearch()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static short[]getSkipArray(byte[] pattern, boolean direction)skipArray Builds a skip array for this pattern and direction.static booleanisEqual(byte[] pattern, byte[] buffer, int start, int end)isEqualstatic intsearch(byte[] search, byte[] bytes, int start, int end, boolean direction)search Look for the search bytes in the bytes array using a straight search.static intskipSearch(byte[] pattern, boolean direction, byte[] buffer, int start, int end, short[] skip)Search a byte sequence for a given pattern.
-
-
-
Method Detail
-
skipSearch
public static int skipSearch(byte[] pattern, boolean direction, byte[] buffer, int start, int end, short[] skip)Search a byte sequence for a given pattern. The method uses the skip search algorithm. The search can be performed in forward or backward direction, i.e. beginning from the start or end of the byte sequence.- Parameters:
pattern- byte[]direction- true if forward, false if backwardbuffer- byte[] to searchstart- index to start searchend- index to end search (end index is not within the search)skip- short[256] A skipArray generated from a call to generateSkipArray.- Returns:
- index or -1 if not found
-
getSkipArray
public static short[] getSkipArray(byte[] pattern, boolean direction)skipArray Builds a skip array for this pattern and direction. The skipArray is used in the optimized skipSearch- Parameters:
pattern-direction-- Returns:
- short[256]
-
isEqual
public static boolean isEqual(byte[] pattern, byte[] buffer, int start, int end)isEqual- Parameters:
pattern-buffer-start- indexend- index- Returns:
- true if the bytes in buffer[start] equal pattern
-
search
public static int search(byte[] search, byte[] bytes, int start, int end, boolean direction)search Look for the search bytes in the bytes array using a straight search. Use the skip search if the number of bytes to search is large or if this search is performed frequently.- Parameters:
search- byte[]bytes- byte[] to searchstart- starting indexend- end index (exclusivedirection- boolean (true indicates forward search, false is backwards search- Returns:
- index or -1
-
-