Class FileCharSequence

java.lang.Object
quickparse.charsequence.FileCharSequence
All Implemented Interfaces:
java.lang.CharSequence

public class FileCharSequence
extends java.lang.Object
implements java.lang.CharSequence
This class defines a wrapper around a text file that is used to efficiently read its content without fully loading it in memory. This implementation uses a strict LRU paging policy. Note that the charAt(int) method does not support long (64 bit) indexing, so that the maximum valid file size is equal to Integer.MAX_VALUE.
Author:
Salvatore Giampa'
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static boolean DEFAULT_IS_UNICODE
    Use unicode as default encoding
    static int DEFAULT_PAGE_SIZE
    Default page size
    static int DEFAULT_PAGES_COUNT
    Default pages count
  • Constructor Summary

    Constructors 
    Constructor Description
    FileCharSequence​(java.io.File file)
    As FileCharSequence(File, int, int, boolean), setting default parameters:
    - pages count: 200;
    - page size: 1048576;
    - is unicode: false;
    FileCharSequence​(java.io.File file, int pagesCount, int pageSize, boolean isUnicode)
    Create a wrapper CharSequence around the specified file
  • Method Summary

    Modifier and Type Method Description
    char charAt​(int index)  
    boolean equals​(java.lang.Object obj)  
    int hashCode()  
    int length()  
    static void main​(java.lang.String[] args)  
    java.lang.CharSequence subSequence​(int start, int end)  
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.CharSequence

    chars, codePoints
  • Field Details

  • Constructor Details

    • FileCharSequence

      public FileCharSequence​(java.io.File file) throws java.io.IOException
      As FileCharSequence(File, int, int, boolean), setting default parameters:
      - pages count: 200;
      - page size: 1048576;
      - is unicode: false;
      Parameters:
      file - the file around which this wrapper would be built
      Throws:
      java.io.IOException - if an I/O error occurs
    • FileCharSequence

      public FileCharSequence​(java.io.File file, int pagesCount, int pageSize, boolean isUnicode) throws java.io.IOException
      Create a wrapper CharSequence around the specified file
      Parameters:
      file - the file around which this wrapper would be built
      pagesCount - the number of caching pages
      pageSize - the size of a cache size
      isUnicode - indicates that the file is encoded on 16-bit Unicode alphabet
      Throws:
      java.io.IOException - if an I/O error occurs, or if the file is larger than Integer.MAX_VALUE, because it cannot be indexed through the charAt(int) method.
  • Method Details

    • charAt

      public char charAt​(int index)
      Specified by:
      charAt in interface java.lang.CharSequence
    • length

      public int length()
      Specified by:
      length in interface java.lang.CharSequence
    • subSequence

      public java.lang.CharSequence subSequence​(int start, int end)
      Specified by:
      subSequence in interface java.lang.CharSequence
    • toString

      public java.lang.String toString()
      Specified by:
      toString in interface java.lang.CharSequence
      Overrides:
      toString in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • main

      public static void main​(java.lang.String[] args) throws java.io.IOException
      Throws:
      java.io.IOException