Package org.passay.dictionary
Class FileWordList
java.lang.Object
org.passay.dictionary.AbstractWordList
org.passay.dictionary.AbstractFileWordList
org.passay.dictionary.FileWordList
- All Implemented Interfaces:
WordList
Provides an implementation of a
WordList that is backed by a file. Each word is read from the file for every
get, though the implementation supports a simple memory cache to improve read performance. This implementation should
be avoided for files greater than 100MB in size.-
Nested Class Summary
Nested classes/interfaces inherited from class org.passay.dictionary.AbstractFileWordList
AbstractFileWordList.FileWord -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BufferWrapper around read buffer.private final byte[]Read buffer.private static final intSize of read buffer.Fields inherited from class org.passay.dictionary.AbstractFileWordList
DEFAULT_CACHE_PERCENT, file, sizeFields inherited from class org.passay.dictionary.AbstractWordList
comparator -
Constructor Summary
ConstructorsConstructorDescriptionFileWordList(RandomAccessFile file) Creates a new case-sensitive word list from the supplied file.FileWordList(RandomAccessFile file, boolean caseSensitive) Creates a new word list from the supplied file.FileWordList(RandomAccessFile file, boolean caseSensitive, int cachePercent) Creates a new word list from the supplied file.FileWordList(RandomAccessFile file, boolean caseSensitive, int cachePercent, CharsetDecoder decoder) Creates a new word list from the supplied file.FileWordList(RandomAccessFile file, boolean caseSensitive, int cachePercent, CharsetDecoder decoder, boolean allocateDirect) Creates a new word list from the supplied file. -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteBufferbuffer()Returns the buffer providing the backing file data.protected voidfill()Fills the buffer from the backing file.protected voidseek(long offset) Positions the read head of the backing file at the given byte offset.Methods inherited from class org.passay.dictionary.AbstractFileWordList
close, get, getFile, initialize, readWord, size, toStringMethods inherited from class org.passay.dictionary.AbstractWordList
checkRange, getComparator, iterator, medianIterator
-
Field Details
-
READ_BUFSIZE
private static final int READ_BUFSIZESize of read buffer.- See Also:
-
bytes
private final byte[] bytesRead buffer. -
buffer
Wrapper around read buffer.
-
-
Constructor Details
-
FileWordList
Creates a new case-sensitive word list from the supplied file. The input file is read on initialization and is maintained by this class.NOTE Attempts to close the source file will cause
IOExceptionwhenAbstractFileWordList.get(int)is called subsequently.- Parameters:
file- File containing words, one per line.- Throws:
IOException- if an error occurs reading the supplied file
-
FileWordList
Creates a new word list from the supplied file. The input file is read on initialization and is maintained by this class.NOTE Attempts to close the source file will cause
IOExceptionwhenAbstractFileWordList.get(int)is called subsequently.- Parameters:
file- File containing words, one per line.caseSensitive- Set to true to create case-sensitive word list, false otherwise.- Throws:
IOException- if an error occurs reading the supplied file
-
FileWordList
public FileWordList(RandomAccessFile file, boolean caseSensitive, int cachePercent) throws IOException Creates a new word list from the supplied file. The input file is read on initialization and is maintained by this class. cachePercent is a percentage of the file size in bytes.NOTE Attempts to close the source file will cause
IOExceptionwhenAbstractFileWordList.get(int)is called subsequently.- Parameters:
file- File containing words, one per line.caseSensitive- Set to true to create case-sensitive word list, false otherwise.cachePercent- Percent (0-100) of file to cache in memory for improved read performance.- Throws:
IllegalArgumentException- if cache percent is out of range.IOException- if an error occurs reading the supplied file
-
FileWordList
public FileWordList(RandomAccessFile file, boolean caseSensitive, int cachePercent, CharsetDecoder decoder) throws IOException Creates a new word list from the supplied file. The input file is read on initialization and is maintained by this class. cachePercent is a percentage of the file size in bytes.NOTE Attempts to close the source file will cause
IOExceptionwhenAbstractFileWordList.get(int)is called subsequently.- Parameters:
file- File containing words, one per line.caseSensitive- Set to true to create case-sensitive word list, false otherwise.cachePercent- Percent (0-100) of file to cache in memory for improved read performance.decoder- Charset decoder for converting file bytes to characters- Throws:
IllegalArgumentException- if cache percent is out of range.IOException- if an error occurs reading the supplied file
-
FileWordList
public FileWordList(RandomAccessFile file, boolean caseSensitive, int cachePercent, CharsetDecoder decoder, boolean allocateDirect) throws IOException Creates a new word list from the supplied file. The input file is read on initialization and is maintained by this class. cachePercent is a percentage of the file size in bytes.NOTE Attempts to close the source file will cause
IOExceptionwhenAbstractFileWordList.get(int)is called subsequently.- Parameters:
file- File containing words, one per line.caseSensitive- Set to true to create case-sensitive word list, false otherwise.cachePercent- Percent (0-100) of file to cache in memory for improved read performance.decoder- Charset decoder for converting file bytes to charactersallocateDirect- whether buffers should be allocated withByteBuffer.allocateDirect(int)- Throws:
IllegalArgumentException- if cache percent is out of range.IOException- if an error occurs reading the supplied file
-
-
Method Details
-
seek
Description copied from class:AbstractFileWordListPositions the read head of the backing file at the given byte offset.- Specified by:
seekin classAbstractFileWordList- Parameters:
offset- byte offset into file.- Throws:
IOException- on I/O errors seeking.
-
buffer
Description copied from class:AbstractFileWordListReturns the buffer providing the backing file data.- Specified by:
bufferin classAbstractFileWordList- Returns:
- Buffer around backing file.
-
fill
Description copied from class:AbstractFileWordListFills the buffer from the backing file. This method may be a no-op if the buffer contains all file contents.- Specified by:
fillin classAbstractFileWordList- Throws:
IOException- on I/O errors filling buffer.
-