public class MemoryMappedFileWordList extends AbstractFileWordList
WordList
that is backed by a file and leverages a MappedByteBuffer
.
Each word is read from the file for every get, though the implementation supports a simple memory cache to improve
read performance. This implementation does not support files greater than 2GB in size. Use this implementation when
the initialization cost of FileWordList
is too high.AbstractFileWordList.FileWord
DEFAULT_CACHE_PERCENT, file, size
comparator
Constructor and Description |
---|
MemoryMappedFileWordList(RandomAccessFile raf)
Creates a new case-sensitive word list from the supplied file.
|
MemoryMappedFileWordList(RandomAccessFile raf,
boolean caseSensitive)
Creates a new word list from the supplied file.
|
MemoryMappedFileWordList(RandomAccessFile raf,
boolean caseSensitive,
int cachePercent)
Creates a new word list from the supplied file.
|
MemoryMappedFileWordList(RandomAccessFile raf,
boolean caseSensitive,
int cachePercent,
CharsetDecoder decoder)
Creates a new word list from the supplied file.
|
MemoryMappedFileWordList(RandomAccessFile raf,
boolean caseSensitive,
int cachePercent,
CharsetDecoder decoder,
boolean allocateDirect)
Creates a new word list from the supplied file.
|
Modifier and Type | Method and Description |
---|---|
protected ByteBuffer |
buffer()
Returns the buffer providing the backing file data.
|
protected void |
fill()
Fills the buffer from the backing file.
|
protected void |
seek(long offset)
Positions the read head of the backing file at the given byte offset.
|
close, get, getFile, initialize, readWord, size, toString
checkIsString, checkRange, getComparator, iterator, medianIterator
public MemoryMappedFileWordList(RandomAccessFile raf) throws IOException
NOTE Attempts to close the source file will cause IOException
when AbstractFileWordList.get(int)
is
called subsequently.
raf
- File containing words, one per line.IOException
- if an error occurs reading the supplied filepublic MemoryMappedFileWordList(RandomAccessFile raf, boolean caseSensitive) throws IOException
NOTE Attempts to close the source file will cause IOException
when AbstractFileWordList.get(int)
is
called subsequently.
raf
- File containing words, one per line.caseSensitive
- Set to true to create case-sensitive word list, false otherwise.IOException
- if an error occurs reading the supplied filepublic MemoryMappedFileWordList(RandomAccessFile raf, boolean caseSensitive, int cachePercent) throws IOException
NOTE Attempts to close the source file will cause IOException
when AbstractFileWordList.get(int)
is
called subsequently.
raf
- 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.IllegalArgumentException
- if cache percent is out of range.IOException
- if an error occurs reading the supplied filepublic MemoryMappedFileWordList(RandomAccessFile raf, boolean caseSensitive, int cachePercent, CharsetDecoder decoder) throws IOException
NOTE Attempts to close the source file will cause IOException
when AbstractFileWordList.get(int)
is
called subsequently.
raf
- 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 charactersIllegalArgumentException
- if cache percent is out of range.IOException
- if an error occurs reading the supplied filepublic MemoryMappedFileWordList(RandomAccessFile raf, boolean caseSensitive, int cachePercent, CharsetDecoder decoder, boolean allocateDirect) throws IOException
NOTE Attempts to close the source file will cause IOException
when AbstractFileWordList.get(int)
is
called subsequently.
raf
- 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 with ByteBuffer.allocateDirect(int)
IllegalArgumentException
- if cache percent is out of range.IOException
- if an error occurs reading the supplied fileprotected void seek(long offset)
AbstractFileWordList
seek
in class AbstractFileWordList
offset
- byte offset into file.protected ByteBuffer buffer()
AbstractFileWordList
buffer
in class AbstractFileWordList
protected void fill()
AbstractFileWordList
fill
in class AbstractFileWordList
Copyright © 2003-2024 Virginia Tech. All Rights Reserved.