public abstract class AbstractFileWordList extends AbstractWordList
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractFileWordList.FileWord
Data structure containing word and byte offset into file where word begins in backing file.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CACHE_PERCENT
Default cache percent.
|
protected RandomAccessFile |
file
File containing words.
|
protected int |
size
Number of words in the file.
|
comparator
Constructor and Description |
---|
AbstractFileWordList(RandomAccessFile raf,
boolean caseSensitive,
CharsetDecoder decoder)
Creates a new abstract file word list from the supplied file.
|
Modifier and Type | Method and Description |
---|---|
protected abstract ByteBuffer |
buffer()
Returns the buffer providing the backing file data.
|
void |
close()
Closes the underlying file and make the cache available for garbage collection.
|
protected abstract void |
fill()
Fills the buffer from the backing file.
|
String |
get(int index)
Returns the word at the given 0-based index.
|
RandomAccessFile |
getFile()
Returns the file backing this list.
|
protected void |
initialize(int cachePercent,
boolean allocateDirect)
Reads words from the backing file to initialize the word list.
|
protected String |
readWord(int index)
Reads the word from the file at the given index of the word list.
|
protected abstract void |
seek(long offset)
Positions the read head of the backing file at the given byte offset.
|
int |
size()
Returns the number of words in the list.
|
String |
toString() |
checkIsString, checkRange, getComparator, iterator, medianIterator
public static final int DEFAULT_CACHE_PERCENT
protected final RandomAccessFile file
protected int size
public AbstractFileWordList(RandomAccessFile raf, boolean caseSensitive, CharsetDecoder decoder)
raf
- File containing words, one per line.caseSensitive
- Set to true to create case-sensitive word list, false otherwise.decoder
- Charset decoder for converting file bytes to characterspublic String get(int index)
WordList
index
- 0-based index.public int size()
WordList
public RandomAccessFile getFile()
public void close() throws IOException
IOException
- if an error occurs closing the fileprotected void initialize(int cachePercent, boolean allocateDirect) throws IOException
cachePercent
- Percent of file in bytes to use for cache.allocateDirect
- whether buffers should be allocated with ByteBuffer.allocateDirect(int)
IllegalArgumentException
- if cachePercent is out of range
or the words are not sorted correctly according to the comparatorIOException
- on I/O errors reading file data.protected String readWord(int index) throws IOException
index
- ith word in the word listIOException
- on I/O errorsprotected abstract void seek(long offset) throws IOException
offset
- byte offset into file.IOException
- on I/O errors seeking.protected abstract ByteBuffer buffer()
protected abstract void fill() throws IOException
IOException
- on I/O errors filling buffer.Copyright © 2003-2024 Virginia Tech. All Rights Reserved.