org.apache.axiom.attachments.utils
Class ByteSearch

java.lang.Object
  extended by 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.


Constructor Summary
ByteSearch()
           
 
Method Summary
static short[] getSkipArray(byte[] pattern, boolean direction)
          skipArray Builds a skip array for this pattern and direction.
static boolean isEqual(byte[] pattern, byte[] buffer, int start, int end)
          isEqual
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.
static int skipSearch(byte[] pattern, boolean direction, byte[] buffer, int start, int end, short[] skip)
          Search a byte sequence for a given pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteSearch

public ByteSearch()
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 backward
buffer - byte[] to search
start - index to start search
end - 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 - index
end - 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 search
start - starting index
end - end index (exclusive
direction - boolean (true indicates forward search, false is backwards search
Returns:
index or -1


Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.