Class FileManagerImpl
- java.lang.Object
-
- net.didion.jwnl.dictionary.file_manager.FileManagerImpl
-
- All Implemented Interfaces:
Remote
,FileManager
,Createable
- Direct Known Subclasses:
RemoteFileManager
public class FileManagerImpl extends Object implements FileManager
An implementation ofFileManager
that reads files from the local file system.FileManagerImpl
caches the file position before and afterreadLineAt
in order to eliminate the redundant IO activity that a naive implementation of these methods would necessitate.
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
FILE_TYPE
public static final String FILE_TYPE
File type install parameter. The value should be the name of the appropriate subclass of DictionaryFileType.- See Also:
- Constant Field Values
-
PATH
public static final String PATH
Dictionary path install parameter. The value should be the absolute path of the directory containing the dictionary files.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FileManagerImpl
public FileManagerImpl()
Uninitialized FileManagerImpl.
-
FileManagerImpl
public FileManagerImpl(String searchDir, Class dictionaryFileType) throws IOException
Construct a file manager backed by a set of files contained in the default WN search directory.- Throws:
IOException
-
-
Method Detail
-
create
public Object create(Map params) throws JWNLException
- Specified by:
create
in interfaceCreateable
- Throws:
JWNLException
-
close
public void close()
Shut down the file manager.- Specified by:
close
in interfaceFileManager
-
getFile
public DictionaryFile getFile(POS pos, DictionaryFileType fileType)
Gets the file from a part of speech and file type (ie data.noun).- Parameters:
pos
- - the part of speech (NOUN, ADJ, VERB, ADV)fileType
- - the file type (data, index, exc)- Returns:
- - dictionary file
-
readLineAt
public String readLineAt(POS pos, DictionaryFileType fileType, long offset) throws IOException
Read the line that begins at file offset offset.- Specified by:
readLineAt
in interfaceFileManager
- Throws:
IOException
-
getNextLinePointer
public long getNextLinePointer(POS pos, DictionaryFileType fileType, long offset) throws IOException
Search for the line following the line that begins at offset.- Specified by:
getNextLinePointer
in interfaceFileManager
- Returns:
- The file offset of the start of the line, or
-1
if offset is the last line in the file. - Throws:
IOException
-
getMatchingLinePointer
public long getMatchingLinePointer(POS pos, DictionaryFileType fileType, long offset, String substring) throws IOException
Search for a line whose index word contains substring, starting at offset.- Specified by:
getMatchingLinePointer
in interfaceFileManager
- Returns:
- The file offset of the start of the matchng line, or
-1
if no such line exists. - Throws:
IOException
-
getIndexedLinePointer
public long getIndexedLinePointer(POS pos, DictionaryFileType fileType, String target) throws IOException
Get indexed line pointer is typically used to find a word within an index file matching a given part of speech. It first accesses the appropriate file (based on pos and dictionary type), then iterates through the file. Does so by using an offset and string comparison algorithm.- Specified by:
getIndexedLinePointer
in interfaceFileManager
- Returns:
- The file offset of the start of the matching line, or
-1
if no such line exists. - Throws:
IOException
-
getRandomLinePointer
public long getRandomLinePointer(POS pos, DictionaryFileType fileType) throws IOException
Return a randomly-chosen line pointer (offset of the beginning of a line).- Specified by:
getRandomLinePointer
in interfaceFileManager
- Returns:
- Throws:
IOException
-
getFirstLinePointer
public long getFirstLinePointer(POS pos, DictionaryFileType fileType) throws IOException
Return the first valid line pointer in the specified file.- Specified by:
getFirstLinePointer
in interfaceFileManager
- Returns:
- Throws:
IOException
-
-