gshute.ioutil
Class LineStream

java.lang.Object
  |
  +--gshute.ioutil.LineStream

public class LineStream
extends java.lang.Object
implements ILineSource

A LineStream dispenses LineScanners for lines read from ILineSources organized as a stack. New ILineSources can be pushed onto the stack by calling insertBatchLines() or insertInteractiveLines(). An ILineSource is automatically popped from the stack when it has no more lines.


Field Summary
protected  java.util.Stack otherSources
          otherSources is the Stack of other sources for this LineStream.
protected  ILineSource topSource
          topSource is the current source for this LineStream.
 
Constructor Summary
LineStream()
          LineStream() returns an empty LineStream.
LineStream(LineSource src)
          LineStream(src) returns a LineStream that begins reading from src.
LineStream(java.lang.String prmt)
          LineStream(prmt) returns a LineStream that begins reading from the terminal using prmt for prompting.
 
Method Summary
 void advance()
          src.advance() advances the input position of src to the next line.
 LineScanner current()
          src.current() returns the line at the current input position of src.
 void endInsert()
          strm.endInsert() terminates an insert begun by insertInteractiveLines() or insertBatchLines().
 Command endInsertCommand(java.lang.String nm)
          strm.endInsertCommand(nm) returns a Command whose name is nm.
 java.lang.String getFileName()
          src.getFileName() Returns the name of the file from which src reads lines.
 int getLineNumber()
          src.getLineNumber() returns the line number of the current line in src.
 void insertBatchLines(java.lang.String fn)
          strm.insertBatchLines(fn) inserts lines read from the file named by fn into the stream of lines read by strm.
 void insertInteractiveLines(java.lang.String prmt)
          strm.insertInteractiveLines(prmt) inserts lines read from the terminal into the stream of lines read by strm.
 Command insertLinesCommand(java.lang.String nm)
          strm.insertLinesCommand(nm) returns a Command whose name is nm.
 boolean more()
          src.more() returns true if there is a line at the current input position of src, false if not.
protected  void push(ILineSource src)
          push(src) pushes topSource onto otherSources and replaces topSource by src.
 void setEchoOff()
          src.setEchoOff() turns echoing off for the top LineSource in src.
 Command setEchoOffCommand(java.lang.String nm)
          strm.setEchoOffCommand(nm) returns a Command whose name is nm.
 void setEchoOn()
          src.setEchoOn() turns echoing on for the top LineSource in src.
 Command setEchoOnCommand(java.lang.String nm)
          strm.setEchoOnCommand(nm) returns a Command whose name is nm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

topSource

protected ILineSource topSource
topSource is the current source for this LineStream.

otherSources

protected java.util.Stack otherSources
otherSources is the Stack of other sources for this LineStream.
Constructor Detail

LineStream

public LineStream()
           throws java.io.IOException,
                  java.io.FileNotFoundException
LineStream() returns an empty LineStream.

LineStream

public LineStream(java.lang.String prmt)
           throws java.io.IOException,
                  java.io.FileNotFoundException
LineStream(prmt) returns a LineStream that begins reading from the terminal using prmt for prompting.

LineStream

public LineStream(LineSource src)
           throws java.io.IOException,
                  java.io.FileNotFoundException
LineStream(src) returns a LineStream that begins reading from src.

Precondition: src is not null.

Method Detail

more

public boolean more()
             throws java.io.IOException
src.more() returns true if there is a line at the current input position of src, false if not.
Specified by:
more in interface ILineSource

current

public LineScanner current()
                    throws java.io.IOException
src.current() returns the line at the current input position of src.

Precondition: src.more() is true.

Specified by:
current in interface ILineSource

advance

public void advance()
             throws java.io.IOException
src.advance() advances the input position of src to the next line.

Precondition: src.more() is true.

Specified by:
advance in interface ILineSource

getLineNumber

public int getLineNumber()
src.getLineNumber() returns the line number of the current line in src.
Specified by:
getLineNumber in interface ILineSource

getFileName

public java.lang.String getFileName()
src.getFileName() Returns the name of the file from which src reads lines.
Specified by:
getFileName in interface ILineSource

setEchoOn

public void setEchoOn()
src.setEchoOn() turns echoing on for the top LineSource in src.
Specified by:
setEchoOn in interface ILineSource

setEchoOff

public void setEchoOff()
src.setEchoOff() turns echoing off for the top LineSource in src.
Specified by:
setEchoOff in interface ILineSource

insertBatchLines

public void insertBatchLines(java.lang.String fn)
                      throws java.io.FileNotFoundException,
                             java.io.IOException
strm.insertBatchLines(fn) inserts lines read from the file named by fn into the stream of lines read by strm.

insertInteractiveLines

public void insertInteractiveLines(java.lang.String prmt)
                            throws java.io.IOException
strm.insertInteractiveLines(prmt) inserts lines read from the terminal into the stream of lines read by strm. prmt is used to prompt for lines.

endInsert

public void endInsert()
strm.endInsert() terminates an insert begun by insertInteractiveLines() or insertBatchLines().

setEchoOnCommand

public Command setEchoOnCommand(java.lang.String nm)
strm.setEchoOnCommand(nm) returns a Command whose name is nm. When this Command is executed, it turns echoing on for the current file in strm. This has no effect if the current file is interactive. The Command ignores its arguments.

setEchoOffCommand

public Command setEchoOffCommand(java.lang.String nm)
strm.setEchoOffCommand(nm) returns a Command whose name is nm. When this Command is executed, it turns echoing off for the current file in strm. This has no effect if the current file is interactive. The Command ignores its arguments.

insertLinesCommand

public Command insertLinesCommand(java.lang.String nm)
strm.insertLinesCommand(nm) returns a Command whose name is nm. When this Command is executed, it inserts lines read from a file into the stream of lines read by strm. If there are one or more argument tokens passed to the Command then the inserted lines are read from the file that is named by the first token. Otherwise, the inserted lines are read from the terminal. The Command ignores its remaining arguments.

endInsertCommand

public Command endInsertCommand(java.lang.String nm)
strm.endInsertCommand(nm) returns a Command whose name is nm. When this Command is executed, it terminates the currently active insert. The Command ignores its arguments.

push

protected void push(ILineSource src)
             throws java.io.IOException
push(src) pushes topSource onto otherSources and replaces topSource by src.