net.didion.jwnl.dictionary.file_manager
Class FileManagerImpl

java.lang.Object
  extended bynet.didion.jwnl.dictionary.file_manager.FileManagerImpl
All Implemented Interfaces:
Createable, FileManager, java.rmi.Remote
Direct Known Subclasses:
RemoteFileManager

public class FileManagerImpl
extends java.lang.Object
implements FileManager

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
static java.lang.String FILE_TYPE
          File type install parameter.
static java.lang.String PATH
          Dictionary path install parameter.
 
Constructor Summary
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
 void close()
          Shut down the file manager.
 java.lang.Object create(java.util.Map params)
           
 DictionaryFile getFile(POS pos, DictionaryFileType fileType)
           
 long getFirstLinePointer(POS pos, DictionaryFileType fileType)
          Return the first valid line pointer in the specified file.
 long getIndexedLinePointer(POS pos, DictionaryFileType fileType, java.lang.String target)
          Search for the line whose first word is index (that is, that begins with index followed by a space or tab).
 long getMatchingLinePointer(POS pos, DictionaryFileType fileType, long offset, java.lang.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).
 java.lang.String readLineAt(POS pos, DictionaryFileType fileType, long offset)
          Read the line that begins at file offset offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

FileManagerImpl

public FileManagerImpl()

FileManagerImpl

public FileManagerImpl(java.lang.String searchDir,
                       java.lang.Class dictionaryFileType)
                throws java.io.IOException
Construct a file manager backed by a set of files contained in the default WN search directory.

Method Detail

create

public java.lang.Object create(java.util.Map params)
                        throws JWNLException
Specified by:
create in interface Createable
Throws:
JWNLException

close

public void close()
Description copied from interface: FileManager
Shut down the file manager.

Specified by:
close in interface FileManager

getFile

public DictionaryFile getFile(POS pos,
                              DictionaryFileType fileType)

readLineAt

public java.lang.String readLineAt(POS pos,
                                   DictionaryFileType fileType,
                                   long offset)
                            throws java.io.IOException
Description copied from interface: FileManager
Read the line that begins at file offset offset.

Specified by:
readLineAt in interface FileManager
Throws:
java.io.IOException

getNextLinePointer

public long getNextLinePointer(POS pos,
                               DictionaryFileType fileType,
                               long offset)
                        throws java.io.IOException
Description copied from interface: FileManager
Search for the line following the line that begins at offset.

Specified by:
getNextLinePointer in interface FileManager
Returns:
The file offset of the start of the line, or -1 if 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
Description copied from interface: FileManager
Search for a line whose index word contains substring, starting at offset.

Specified by:
getMatchingLinePointer in interface FileManager
Returns:
The file offset of the start of the matchng line, or -1 if no such line exists.
Throws:
java.io.IOException

getIndexedLinePointer

public long getIndexedLinePointer(POS pos,
                                  DictionaryFileType fileType,
                                  java.lang.String target)
                           throws java.io.IOException
Description copied from interface: FileManager
Search for the line whose first word is index (that is, that begins with index followed by a space or tab).

Specified by:
getIndexedLinePointer in interface FileManager
Returns:
The file offset of the start of the matching line, or -1 if no such line exists.
Throws:
java.io.IOException

getRandomLinePointer

public long getRandomLinePointer(POS pos,
                                 DictionaryFileType fileType)
                          throws java.io.IOException
Description copied from interface: FileManager
Return a randomly-chosen line pointer (offset of the beginning of a line).

Specified by:
getRandomLinePointer in interface FileManager
Parameters:
pos -
fileType -
Returns:
Throws:
java.io.IOException

getFirstLinePointer

public long getFirstLinePointer(POS pos,
                                DictionaryFileType fileType)
                         throws java.io.IOException
Description copied from interface: FileManager
Return the first valid line pointer in the specified file.

Specified by:
getFirstLinePointer in interface FileManager
Parameters:
pos -
fileType -
Returns:
Throws:
java.io.IOException



JWNL homepage.