Class FileManagerImpl
java.lang.Object
net.didion.jwnl.dictionary.file_manager.FileManagerImpl
- All Implemented Interfaces:
Remote,FileManager,Createable
- Direct Known Subclasses:
RemoteFileManager
An implementation of
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.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionUninitialized 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
Modifier and TypeMethodDescriptionprivate voidChecks the type to ensure it's valid.voidclose()Shut down the file manager.getFile(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, 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, 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).readLineAt(POS pos, DictionaryFileType fileType, long offset) Read the line that begins at file offset offset.private StringReads the first word from a file (ie offset, index word)private voidSkips the next line in the file.
-
Field Details
-
FILE_TYPE
File type install parameter. The value should be the name of the appropriate subclass of DictionaryFileType.- See Also:
-
PATH
Dictionary path install parameter. The value should be the absolute path of the directory containing the dictionary files.- See Also:
-
_rand
Random number generator used by getRandomLineOffset(). -
_files
The catalog set.
-
-
Constructor Details
-
FileManagerImpl
public FileManagerImpl()Uninitialized FileManagerImpl. -
FileManagerImpl
Construct a file manager backed by a set of files contained in the default WN search directory.- Throws:
IOException
-
-
Method Details
-
create
- Specified by:
createin interfaceCreateable- Throws:
JWNLException
-
checkFileType
Checks the type to ensure it's valid.- Parameters:
c-
-
close
public void close()Shut down the file manager.- Specified by:
closein interfaceFileManager
-
getFile
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
Skips the next line in the file.- Parameters:
file-- Throws:
IOException
-
readLineAt
Read the line that begins at file offset offset.- Specified by:
readLineAtin interfaceFileManager- Throws:
IOException
-
readLineWord
Reads the first word from a file (ie offset, index word)- Parameters:
file- - the file- Returns:
- - string
- 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:
getNextLinePointerin interfaceFileManager- Returns:
- The file offset of the start of the line, or
-1if 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:
getMatchingLinePointerin interfaceFileManager- Returns:
- The file offset of the start of the matchng line, or
-1if 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:
getIndexedLinePointerin interfaceFileManager- Returns:
- The file offset of the start of the matching line, or
-1if no such line exists. - Throws:
IOException
-
getRandomLinePointer
Return a randomly-chosen line pointer (offset of the beginning of a line).- Specified by:
getRandomLinePointerin interfaceFileManager- Parameters:
pos-fileType-- Returns:
- Throws:
IOException
-
getFirstLinePointer
Return the first valid line pointer in the specified file.- Specified by:
getFirstLinePointerin interfaceFileManager- Parameters:
pos-fileType-- Returns:
- Throws:
IOException
-