Class BinFileSearcher

java.lang.Object
org.riversun.bigdoc.bin.BinFileSearcher

public class BinFileSearcher extends Object
Search sequence of bytes from Binary file
Author:
Tom Misawa (riversun.org@gmail.com)
  • Field Details

    • DEFAULT_BUFFER_SIZE

      public static final int DEFAULT_BUFFER_SIZE
      Default size to be read into memory at one search
      See Also:
    • DEFAULT_SUB_BUFFER_SIZE

      public static final int DEFAULT_SUB_BUFFER_SIZE
      Default number of threads used at the same time in one search
      See Also:
    • DEFAULT_SUB_THREAD_SIZE

      public static final int DEFAULT_SUB_THREAD_SIZE
      Dfault size of the window used to scan memory
      See Also:
  • Constructor Details

    • BinFileSearcher

      public BinFileSearcher()
  • Method Details

    • cancel

      public void cancel()
    • setBufferSize

      public void setBufferSize(int bufferSize)
      Set size to be read into memory at one search
      Parameters:
      bufferSize -
    • setSubThreadSize

      public void setSubThreadSize(int subThreadSize)
      Set number of threads used at the same time in one search
      Parameters:
      subThreadSize -
    • setSubBufferSize

      public void setSubBufferSize(int subBufferSize)
      Set the size of the window used to scan memory
      Parameters:
      subBufferSize -
    • setBigFileProgressListener

      public void setBigFileProgressListener(BinFileSearcher.BinFileProgressListener listener)
      Set the listener that callbacks the search-progress
      Parameters:
      listener -
    • indexOf

      public Long indexOf(File f, byte[] searchBytes)
      Returns the index within this file of the first occurrence of the specified substring.
      Parameters:
      f -
      searchBytes -
      Returns:
    • indexOf

      public Long indexOf(File f, byte[] searchBytes, long fromPosition)
      Returns the index within this file of the first occurrence of the specified substring, starting at the specified position.
      Parameters:
      f - target file
      searchBytes - a sequence of bytes you want to find
      fromPosition - "0" means the beginning of the file
      Returns:
      position of the first occurence. '-1' means that it was not found.
    • search

      public List<Long> search(File f, byte[] searchBytes)
      Parameters:
      f -
      searchBytes -
      Returns:
    • searchPartially

      public List<Long> searchPartially(File f, byte[] searchBytes, long startPosition, long maxSizeToRead)
      Search for a sequence of bytes from the file within the specified size range starting at the specified position .
      Parameters:
      f -
      searchBytes - a sequence of bytes you want to find
      startPosition - '0' means the beginning of the file
      maxSizeToRead - max size to read.'-1' means read until the end.
      Returns:
    • searchPartiallyUsingNIO

      protected List<Long> searchPartiallyUsingNIO(File f, byte[] searchBytes, long startPosition, long maxSizeToRead, BinFileSearcher.BinFileProgressListener listener)
    • sort

      protected void sort(List<Long> list)
    • stop

      public void stop()
      Stop searching bytes