Class BigFileSearcher

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

public class BigFileSearcher extends Object
Search bytes from big file
Available for giga-bytes order file
Author:
Tom Misawa (riversun.org@gmail.com)
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    List<org.riversun.bigdoc.bin.BigFileSearcher.BigFileSearchTask>
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Profiling method
    void
    Cancel searching
    long
    Get operation time in millis of last search
    indexOf(File f, byte[] searchBytes)
    Returns the index within this file of the first occurrence of the specified substring.
    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.
    searchBigFile(File f, byte[] searchBytes)
    Search bytes from big file faster in a concurrent processing with progress callback
    searchBigFile(File f, byte[] searchBytes, BigFileSearcher.OnProgressListener listener)
    Search bytes from big file faster in a concurrent processing with progress callback
     
    searchBigFileRealtime(File f, byte[] searchBytes, long startPosition, BigFileSearcher.OnRealtimeResultListener listener)
    * Search bytes from big file faster with realtime result callback

    This callbacks the result in real time, but since the concurrency is inferior to #searchBigFile,so the execution speed is slower than #searchBigFile
    Search bytes from big file faster with realtime result callback

    This callbacks the result in real time, but since the concurrency is inferior to #searchBigFile,so the execution speed is slower than #searchBigFile
    void
    setBlockSize(long blockSize)
    Set size per unit when divide loading big sized file into multiple pieces

    In order to make this method effective,call setUseOptimization(false) to turn off the optimization.
    void
    setBufferSizePerWorker(int bufferSize)
    Set size to be read into memory at one search
    In order to make this method effective,call setUseOptimization(false) to turn off the optimization.
    void
    setMaxNumOfThreads(int maxNumOfThreads)
    Set max number of thread to concurrent load to file
    Increased the number of threads does not means improving a performance

    In order to make this method effective,call setUseOptimization(false) to turn off the optimization.
    void
    setSubBufferSize(int subBufferSize)
    Set the size of the window used to scan memory used in each worker
    In order to make this method effective,call setUseOptimization(false) to turn off the optimization.
    void
    setSubThreadSize(int subThreadSize)
    Set number of threads used in each worker
    In order to make this method effective,call setUseOptimization(false) to turn off the optimization.
    void
    setUseOptimization(boolean enabled)
    Use memory and threading optimization
    (default is true)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_MAX_NUM_OF_THREADS

      public static final int DEFAULT_MAX_NUM_OF_THREADS
      See Also:
    • THREADS_NO_LIMIT

      public static final int THREADS_NO_LIMIT
      See Also:
    • DEFAULT_BLOCK_SIZE

      public static final int DEFAULT_BLOCK_SIZE
      See Also:
    • mTaskList

      public List<org.riversun.bigdoc.bin.BigFileSearcher.BigFileSearchTask> mTaskList
  • Constructor Details

    • BigFileSearcher

      public BigFileSearcher()
  • Method Details

    • setUseOptimization

      public void setUseOptimization(boolean enabled)
      Use memory and threading optimization
      (default is true)
      Parameters:
      enabled - optimization enabled or not
    • setBlockSize

      public void setBlockSize(long blockSize)
      Set size per unit when divide loading big sized file into multiple pieces

      In order to make this method effective,call setUseOptimization(false) to turn off the optimization.
      Parameters:
      blockSize - size per unit when divide loading big sized file
    • setBufferSizePerWorker

      public void setBufferSizePerWorker(int bufferSize)
      Set size to be read into memory at one search
      In order to make this method effective,call setUseOptimization(false) to turn off the optimization.
      Parameters:
      bufferSize - size(byte) to be read into memory at one search operation
    • setMaxNumOfThreads

      public void setMaxNumOfThreads(int maxNumOfThreads)
      Set max number of thread to concurrent load to file
      Increased the number of threads does not means improving a performance

      In order to make this method effective,call setUseOptimization(false) to turn off the optimization.
      Parameters:
      maxNumOfThreads - number of threads(concurrency)
    • setSubThreadSize

      public void setSubThreadSize(int subThreadSize)
      Set number of threads used in each worker
      In order to make this method effective,call setUseOptimization(false) to turn off the optimization.
      Parameters:
      subThreadSize - number of threads for sub threads(concurrency)
    • setSubBufferSize

      public void setSubBufferSize(int subBufferSize)
      Set the size of the window used to scan memory used in each worker
      In order to make this method effective,call setUseOptimization(false) to turn off the optimization.
      Parameters:
      subBufferSize - size(bytes) of the window
    • indexOf

      public Long indexOf(File f, byte[] searchBytes)
      Returns the index within this file of the first occurrence of the specified substring.
      Parameters:
      f - target file
      searchBytes - sequence of bytes you want to search
      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.
    • searchBigFileRealtime

      public List<Long> searchBigFileRealtime(File f, byte[] searchBytes, BigFileSearcher.OnRealtimeResultListener listener)
      Search bytes from big file faster with realtime result callback

      This callbacks the result in real time, but since the concurrency is inferior to #searchBigFile,so the execution speed is slower than #searchBigFile
      Parameters:
      f - targetFile
      searchBytes - sequence of bytes you want to search
      listener - callback for progress and realtime result
    • searchBigFileRealtime

      public List<Long> searchBigFileRealtime(File f, byte[] searchBytes, long startPosition, BigFileSearcher.OnRealtimeResultListener listener)
      * Search bytes from big file faster with realtime result callback

      This callbacks the result in real time, but since the concurrency is inferior to #searchBigFile,so the execution speed is slower than #searchBigFile
      Parameters:
      f - targetFile
      searchBytes - sequence of bytes you want to search
      startPosition - starting position
      listener - callback for progress and realtime result
      Returns:
    • searchBigFile

      public List<Long> searchBigFile(File f, byte[] searchBytes)
      Search bytes from big file faster in a concurrent processing with progress callback
      Parameters:
      f - target file
      searchBytes - sequence of bytes you want to search
      Returns:
    • searchBigFile

      public List<Long> searchBigFile(File f, byte[] searchBytes, BigFileSearcher.OnProgressListener listener)
      Search bytes from big file faster in a concurrent processing with progress callback
      Parameters:
      f - target file
      searchBytes - sequence of bytes you want to search
      listener - callback for progress
      Returns:
    • cancel

      public void cancel()
      Cancel searching
    • searchBigFile

      public List<Long> searchBigFile(SearchCondition sc)
    • getEllapsedMillis

      public long getEllapsedMillis()
      Get operation time in millis of last search
      Returns:
    • _showProfile

      public void _showProfile()
      Profiling method