Class FileManagerImpl
- java.lang.Object
-
- net.didion.jwnl.dictionary.file_manager.FileManagerImpl
-
- All Implemented Interfaces:
java.rmi.Remote,FileManager,Createable
- Direct Known Subclasses:
RemoteFileManager
public class FileManagerImpl extends java.lang.Object implements FileManager
An implementation ofFileManagerthat reads files from the local file system.FileManagerImplcaches the file position before and afterreadLineAtin order to eliminate the redundant IO activity that a naive implementation of these methods would necessitate.
-
-
Field Summary
Fields Modifier and Type Field Description private DictionaryCatalogSet_filesThe catalog set.private static java.util.Random_randRandom number generator used by getRandomLineOffset().static java.lang.StringFILE_TYPEFile type install parameter.static java.lang.StringPATHDictionary path install parameter.
-
Constructor Summary
Constructors Constructor Description FileManagerImpl()Uninitialized FileManagerImpl.FileManagerImpl(java.lang.String searchDir, java.lang.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 private voidcheckFileType(java.lang.Class c)Checks the type to ensure it's valid.voidclose()Shut down the file manager.java.lang.Objectcreate(java.util.Map params)DictionaryFilegetFile(POS pos, DictionaryFileType fileType)Gets the file from a part of speech and file type (ie data.noun).longgetFirstLinePointer(POS pos, DictionaryFileType fileType)Return the first valid line pointer in the specified file.longgetIndexedLinePointer(POS pos, DictionaryFileType fileType, java.lang.String target)Get indexed line pointer is typically used to find a word within an index file matching a given part of speech.longgetMatchingLinePointer(POS pos, DictionaryFileType fileType, long offset, java.lang.String substring)Search for a line whose index word contains substring, starting at offset.longgetNextLinePointer(POS pos, DictionaryFileType fileType, long offset)Search for the line following the line that begins at offset.longgetRandomLinePointer(POS pos, DictionaryFileType fileType)Return a randomly-chosen line pointer (offset of the beginning of a line).java.lang.StringreadLineAt(POS pos, DictionaryFileType fileType, long offset)Read the line that begins at file offset offset.private java.lang.StringreadLineWord(RandomAccessDictionaryFile file)Reads the first word from a file (ie offset, index word)private voidskipLine(RandomAccessDictionaryFile file)Skips the next line in the file.
-
-
-
Field Detail
-
FILE_TYPE
public static final java.lang.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 java.lang.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
-
_rand
private static final java.util.Random _rand
Random number generator used by getRandomLineOffset().
-
_files
private DictionaryCatalogSet _files
The catalog set.
-
-
Constructor Detail
-
FileManagerImpl
public FileManagerImpl()
Uninitialized FileManagerImpl.
-
FileManagerImpl
public FileManagerImpl(java.lang.String searchDir, java.lang.Class dictionaryFileType) throws java.io.IOExceptionConstruct a file manager backed by a set of files contained in the default WN search directory.- Throws:
java.io.IOException
-
-
Method Detail
-
create
public java.lang.Object create(java.util.Map params) throws JWNLException- Specified by:
createin interfaceCreateable- Throws:
JWNLException
-
checkFileType
private void checkFileType(java.lang.Class c)
Checks the type to ensure it's valid.- Parameters:
c-
-
close
public void close()
Shut down the file manager.- Specified by:
closein 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
-
skipLine
private void skipLine(RandomAccessDictionaryFile file) throws java.io.IOException
Skips the next line in the file.- Parameters:
file-- Throws:
java.io.IOException
-
readLineAt
public java.lang.String readLineAt(POS pos, DictionaryFileType fileType, long offset) throws java.io.IOException
Read the line that begins at file offset offset.- Specified by:
readLineAtin interfaceFileManager- Throws:
java.io.IOException
-
readLineWord
private java.lang.String readLineWord(RandomAccessDictionaryFile file) throws java.io.IOException
Reads the first word from a file (ie offset, index word)- Parameters:
file- - the file- Returns:
- - string
- Throws:
java.io.IOException
-
getNextLinePointer
public long getNextLinePointer(POS pos, DictionaryFileType fileType, long offset) throws java.io.IOException
Search for the line following the line that begins at offset.- Specified by:
getNextLinePointerin interfaceFileManager- Returns:
- The file offset of the start of the line, or
-1if offset is the last line in the file. - Throws:
java.io.IOException
-
getMatchingLinePointer
public long getMatchingLinePointer(POS pos, DictionaryFileType fileType, long offset, java.lang.String substring) throws java.io.IOException
Search for a line whose index word contains substring, starting at offset.- Specified by:
getMatchingLinePointerin interfaceFileManager- Returns:
- The file offset of the start of the matchng line, or
-1if no such line exists. - Throws:
java.io.IOException
-
getIndexedLinePointer
public long getIndexedLinePointer(POS pos, DictionaryFileType fileType, java.lang.String target) throws java.io.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:
getIndexedLinePointerin interfaceFileManager- Returns:
- The file offset of the start of the matching line, or
-1if no such line exists. - Throws:
java.io.IOException
-
getRandomLinePointer
public long getRandomLinePointer(POS pos, DictionaryFileType fileType) throws java.io.IOException
Return a randomly-chosen line pointer (offset of the beginning of a line).- Specified by:
getRandomLinePointerin interfaceFileManager- Returns:
- Throws:
java.io.IOException
-
getFirstLinePointer
public long getFirstLinePointer(POS pos, DictionaryFileType fileType) throws java.io.IOException
Return the first valid line pointer in the specified file.- Specified by:
getFirstLinePointerin interfaceFileManager- Returns:
- Throws:
java.io.IOException
-
-