public class FileManagerImpl extends Object implements FileManager
FileManager
that reads files from the local file system.
FileManagerImpl
caches the file position before and after readLineAt
in order to eliminate the redundant IO activity that a naive implementation of these methods
would necessitate.Modifier and Type | Field and Description |
---|---|
static String |
FILE_TYPE
File type install parameter.
|
static String |
PATH
Dictionary path install parameter.
|
Constructor and Description |
---|
FileManagerImpl()
Uninitialized FileManagerImpl.
|
FileManagerImpl(String searchDir,
Class dictionaryFileType)
Construct a file manager backed by a set of files contained
in the default WN search directory.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Shut down the file manager.
|
Object |
create(Map params) |
DictionaryFile |
getFile(POS pos,
DictionaryFileType fileType)
Gets the file from a part of speech and file type (ie data.noun).
|
long |
getFirstLinePointer(POS pos,
DictionaryFileType fileType)
Return the first valid line pointer in the specified file.
|
long |
getIndexedLinePointer(POS pos,
DictionaryFileType fileType,
String target)
Get indexed line pointer is typically used to find a word within an index file matching a given part of speech.
|
long |
getMatchingLinePointer(POS pos,
DictionaryFileType fileType,
long offset,
String substring)
Search for a line whose index word contains substring, starting at offset.
|
long |
getNextLinePointer(POS pos,
DictionaryFileType fileType,
long offset)
Search for the line following the line that begins at offset.
|
long |
getRandomLinePointer(POS pos,
DictionaryFileType fileType)
Return a randomly-chosen line pointer (offset of the beginning of a line).
|
String |
readLineAt(POS pos,
DictionaryFileType fileType,
long offset)
Read the line that begins at file offset offset.
|
public static final String FILE_TYPE
public static final String PATH
public FileManagerImpl()
public FileManagerImpl(String searchDir, Class dictionaryFileType) throws IOException
IOException
public Object create(Map params) throws JWNLException
create
in interface Createable
JWNLException
public void close()
close
in interface FileManager
public DictionaryFile getFile(POS pos, DictionaryFileType fileType)
pos
- - the part of speech (NOUN, ADJ, VERB, ADV)fileType
- - the file type (data, index, exc)public String readLineAt(POS pos, DictionaryFileType fileType, long offset) throws IOException
readLineAt
in interface FileManager
IOException
public long getNextLinePointer(POS pos, DictionaryFileType fileType, long offset) throws IOException
getNextLinePointer
in interface FileManager
-1
if offset
is the last line in the file.IOException
public long getMatchingLinePointer(POS pos, DictionaryFileType fileType, long offset, String substring) throws IOException
getMatchingLinePointer
in interface FileManager
-1
if
no such line exists.IOException
public long getIndexedLinePointer(POS pos, DictionaryFileType fileType, String target) throws IOException
getIndexedLinePointer
in interface FileManager
-1
if no such line exists.IOException
public long getRandomLinePointer(POS pos, DictionaryFileType fileType) throws IOException
getRandomLinePointer
in interface FileManager
IOException
public long getFirstLinePointer(POS pos, DictionaryFileType fileType) throws IOException
getFirstLinePointer
in interface FileManager
IOException
Copyright © 2023. All rights reserved.