Package quickparse.charsequence
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 booleanDEFAULT_IS_UNICODEUse unicode as default encodingstatic intDEFAULT_PAGE_SIZEDefault page sizestatic intDEFAULT_PAGES_COUNTDefault pages count -
Constructor Summary
Constructors Constructor Description FileCharSequence(java.io.File file)AsFileCharSequence(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
-
Field Details
-
DEFAULT_PAGE_SIZE
public static final int DEFAULT_PAGE_SIZEDefault page size- See Also:
- Constant Field Values
-
DEFAULT_PAGES_COUNT
public static final int DEFAULT_PAGES_COUNTDefault pages count- See Also:
- Constant Field Values
-
DEFAULT_IS_UNICODE
public static final boolean DEFAULT_IS_UNICODEUse unicode as default encoding- See Also:
- Constant Field Values
-
-
Constructor Details
-
FileCharSequence
public FileCharSequence(java.io.File file) throws java.io.IOExceptionAsFileCharSequence(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.IOExceptionCreate a wrapper CharSequence around the specified file- Parameters:
file- the file around which this wrapper would be builtpagesCount- the number of caching pagespageSize- the size of a cache sizeisUnicode- 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 thanInteger.MAX_VALUE, because it cannot be indexed through thecharAt(int)method.
-
-
Method Details
-
charAt
public char charAt(int index)- Specified by:
charAtin interfacejava.lang.CharSequence
-
length
public int length()- Specified by:
lengthin interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)- Specified by:
subSequencein interfacejava.lang.CharSequence
-
toString
public java.lang.String toString()- Specified by:
toStringin interfacejava.lang.CharSequence- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
main
public static void main(java.lang.String[] args) throws java.io.IOException- Throws:
java.io.IOException
-