edu.brandeis.cs.steele.wn
Class FileManager

java.lang.Object
  extended by edu.brandeis.cs.steele.wn.FileManager
All Implemented Interfaces:
FileManagerInterface, java.rmi.Remote
Direct Known Subclasses:
RemoteFileManager

public class FileManager
extends java.lang.Object
implements FileManagerInterface

An implementation of FileManagerInterface that reads files from the local file system. a file. FileManager 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. Instances of this class are guarded. Operations are synchronized by file.

Author:
Oliver Steele, steele@cs.brandeis.edu

Nested Class Summary
protected  class FileManager.NextLineCache
           
 
Field Summary
protected  java.util.Hashtable<java.lang.String,java.io.RandomAccessFile> filenameCache
           
protected static java.lang.String fileSeparator
           
protected static boolean IS_MAC_OS
           
protected static boolean IS_MW_VM
           
protected static boolean IS_WINDOWS_OS
           
protected  FileManager.NextLineCache nextLineCache
           
protected  java.lang.String searchDirectory
           
static boolean TRACE_LOOKUP
          Set this to true to enable debugging messages in getIndexedLinePointer.
static java.lang.String VERSION
          The API version, used by RemoteFileManager for constructing a binding name.
 
Constructor Summary
FileManager()
          Construct a file manager backed by a set of files contained in the default WN search directory.
FileManager(java.lang.String searchDirectory)
          Construct a file manager backed by a set of files contained in searchDirectory.
 
Method Summary
protected  int compare(java.lang.String a, java.lang.String b)
          Return a negative value if a precedes b, a positive value if a follows b, otherwise 0.
protected  java.io.RandomAccessFile getFileStream(java.lang.String filename)
           
 long getIndexedLinePointer(java.lang.String filename, 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(java.lang.String filename, long offset, java.lang.String substring)
          Search for a line whose index word contains substring.
 long getNextLinePointer(java.lang.String filename, long offset)
          Search for the line following the line that begins at offset.
protected static java.lang.String getWNHome()
           
protected static java.lang.String getWNSearchDir()
           
(package private) static java.lang.String mapToWindowsFilename(java.lang.String filename)
           
protected  java.lang.String readLine(java.io.RandomAccessFile stream)
           
 java.lang.String readLineAt(java.lang.String filename, long offset)
          Read the line that begins at file offset offset in the file named by filename.
protected  java.lang.String readLineWord(java.io.RandomAccessFile stream)
           
protected  void skipLine(java.io.RandomAccessFile stream)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static java.lang.String VERSION
The API version, used by RemoteFileManager for constructing a binding name.


TRACE_LOOKUP

public static final boolean TRACE_LOOKUP
Set this to true to enable debugging messages in getIndexedLinePointer.

See Also:
Constant Field Values

IS_MW_VM

protected static final boolean IS_MW_VM

searchDirectory

protected java.lang.String searchDirectory

filenameCache

protected java.util.Hashtable<java.lang.String,java.io.RandomAccessFile> filenameCache

nextLineCache

protected FileManager.NextLineCache nextLineCache

IS_WINDOWS_OS

protected static final boolean IS_WINDOWS_OS

IS_MAC_OS

protected static final boolean IS_MAC_OS

fileSeparator

protected static final java.lang.String fileSeparator
Constructor Detail

FileManager

public FileManager()
Construct a file manager backed by a set of files contained in the default WN search directory. The default search directory is the location named by the system property WNSEARCHDIR; or, if this is undefined, by the directory named WNHOME/Database (under MacOS) or WNHOME/dict (otherwise); or, if the WNHOME is undefined, the current directory (under MacOS), "C:\wn16" (WIndows), or "/usr/local/wordnet1.6" (otherwise).


FileManager

public FileManager(java.lang.String searchDirectory)
Construct a file manager backed by a set of files contained in searchDirectory.

Method Detail

getWNHome

protected static java.lang.String getWNHome()

getWNSearchDir

protected static java.lang.String getWNSearchDir()

mapToWindowsFilename

static java.lang.String mapToWindowsFilename(java.lang.String filename)

getFileStream

protected java.io.RandomAccessFile getFileStream(java.lang.String filename)
                                          throws java.io.IOException
Throws:
java.io.IOException

readLine

protected java.lang.String readLine(java.io.RandomAccessFile stream)
                             throws java.io.IOException
Throws:
java.io.IOException

skipLine

protected void skipLine(java.io.RandomAccessFile stream)
                 throws java.io.IOException
Throws:
java.io.IOException

readLineAt

public java.lang.String readLineAt(java.lang.String filename,
                                   long offset)
                            throws java.io.IOException
Description copied from interface: FileManagerInterface
Read the line that begins at file offset offset in the file named by filename.

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

readLineWord

protected java.lang.String readLineWord(java.io.RandomAccessFile stream)
                                 throws java.io.IOException
Throws:
java.io.IOException

getNextLinePointer

public long getNextLinePointer(java.lang.String filename,
                               long offset)
                        throws java.io.IOException
Description copied from interface: FileManagerInterface
Search for the line following the line that begins at offset.

Specified by:
getNextLinePointer in interface FileManagerInterface
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(java.lang.String filename,
                                   long offset,
                                   java.lang.String substring)
                            throws java.io.IOException
Description copied from interface: FileManagerInterface
Search for a line whose index word contains substring.

Specified by:
getMatchingLinePointer in interface FileManagerInterface
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(java.lang.String filename,
                                  java.lang.String target)
                           throws java.io.IOException
Description copied from interface: FileManagerInterface
Search for the line whose first word is index (that is, that begins with index followed by a space or tab). filename must name a file whose lines are sorted by index word.

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

compare

protected int compare(java.lang.String a,
                      java.lang.String b)
Return a negative value if a precedes b, a positive value if a follows b, otherwise 0.