ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

javafe.util
Class FileCorrelatedReader

java.lang.Object
  extended byjavafe.util.CorrelatedReader
      extended byjavafe.util.BufferedCorrelatedReader
          extended byjavafe.util.LocationManagerCorrelatedReader
              extended byjavafe.util.FileCorrelatedReader

public class FileCorrelatedReader
extends LocationManagerCorrelatedReader

A FileCorrelatedReader is a CorrelatedReader that reads its characters from a stream that corresponds to a file.

The class also provides a method to create a new CorrelatedReader for the text between the marked position and the current point in the stream.

Author:
Cormac Flanagan, Rustan Leino
See Also:
Location

Field Summary
private static int DEFAULTBUFSIZE
          The initial size for buf
private  GenericFile file
          The GenericFile for this CorrelatedReader.
private static int READBLOCKSIZE
          How big a block to read from a stream at a time
private  java.io.InputStream stream
          The stream for this CorrelatedReader if it is open and not a subReader.
 
Fields inherited from class javafe.util.LocationManagerCorrelatedReader
curLineNo, isWholeFile, MAXFILESIZE, streamid, totalLinesRead
 
Fields inherited from class javafe.util.BufferedCorrelatedReader
beforeBufLoc, buf, curNdx, endBufNdx, lastCharNdx, markNdx, maxLoc, minLoc, oddSlashLoc, STARTFREELOC
 
Fields inherited from class javafe.util.CorrelatedReader
marked
 
Constructor Summary
  FileCorrelatedReader(GenericFile file)
          Constructs a correlated input stream that reads its input from the specified GenericFile.
private FileCorrelatedReader(java.io.InputStream in, GenericFile file)
          Constructs a correlated input stream that reads its input from the specified input stream.
  FileCorrelatedReader(java.io.InputStream in, java.lang.String streamName)
          This is a specialized constructor used for InputStreams that are not reopenable such as stdin.
 
Method Summary
 void close()
          Closes us.
(package private) static int createWholeFileLoc(GenericFile file)
          Create a whole file location for a given GenericFile.
 GenericFile getFile()
          Returns the file underlying this correlated reader.
 int read()
          See spec in the abstract CorrelatedReader class.
protected  boolean refillBuf()
          Refills the buffer.
 
Methods inherited from class javafe.util.LocationManagerCorrelatedReader
clear, fileNumbersToNames, getCorrStreamAt, isWholeFileLoc, locToColumn, locToFile, locToLineNumber, locToOffset, locToStream, locToStreamId, makeLocation, mark, recordNewLineLocation, reset, streamIdToFile, toString
 
Methods inherited from class javafe.util.BufferedCorrelatedReader
clearMark, createReaderFromMark, getBeforeMarkLocation, getBufferFromMark, getLocation, peek, readRaw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

READBLOCKSIZE

private static final int READBLOCKSIZE
How big a block to read from a stream at a time

See Also:
Constant Field Values

DEFAULTBUFSIZE

private static final int DEFAULTBUFSIZE
The initial size for buf

See Also:
Constant Field Values

stream

private java.io.InputStream stream
The stream for this CorrelatedReader if it is open and not a subReader. Null otherwise. (A CorrelatedReader is defined to be open iff buf is non-null.)


file

private GenericFile file
The GenericFile for this CorrelatedReader.

Constructor Detail

FileCorrelatedReader

public FileCorrelatedReader(GenericFile file)
                     throws java.io.IOException
Constructs a correlated input stream that reads its input from the specified GenericFile.


FileCorrelatedReader

public FileCorrelatedReader(java.io.InputStream in,
                            java.lang.String streamName)
This is a specialized constructor used for InputStreams that are not reopenable such as stdin.

streamName is the human readable name of the stream.


FileCorrelatedReader

private FileCorrelatedReader(java.io.InputStream in,
                             GenericFile file)
Constructs a correlated input stream that reads its input from the specified input stream. file is an associated GenericFile that may be used to reopen the specified input stream

Method Detail

createWholeFileLoc

static int createWholeFileLoc(GenericFile file)
Create a whole file location for a given GenericFile.

file need not be openable.


close

public void close()
Closes us. No other I/O operations may be called on us after we have been closed.

Overrides:
close in class LocationManagerCorrelatedReader

read

public int read()
         throws java.io.IOException
See spec in the abstract CorrelatedReader class.

Specified by:
read in class CorrelatedReader
Returns:
A unicode character, or -1.

Throws:
java.io.IOException

refillBuf

protected boolean refillBuf()
                     throws java.io.IOException
Refills the buffer.

If the mark is set, and there is less that READBLOCKSIZE space left in the buffer, it allocates a larger buffer and copies markNdx..curNdx from the old buffer into the new one. If the mark is not set, then it clears the buffer. It then tries to read READBLOCKSIZE from the underlying input stream.

Returns true iff not end-of-file, and at least one character was read from the file. Throws an IOException if no characters could be read from the stream.

Requires we are open.

Specified by:
refillBuf in class BufferedCorrelatedReader
Throws:
java.io.IOException

getFile

public GenericFile getFile()
Returns the file underlying this correlated reader.

Specified by:
getFile in class CorrelatedReader

ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage