iglu.util
Class TextFileProcessor

java.lang.Object
  |
  +--iglu.util.TextFileProcessor

public class TextFileProcessor
extends java.lang.Object

Basic functionality for classes that perform a pass on a text file. The main advantages of using this class are that you don't need to deal with IOExceptions, and you get a count of the number of lines processed. Passes can be implemented in two ways:

Author:
Ryan Scherle

Field Summary
private  int linesRead
           
private  java.io.PrintWriter output
           
private  java.io.BufferedReader theReader
           
 
Constructor Summary
TextFileProcessor(java.io.File inputFile, java.io.File outputFile)
          Constructs a simple pass, but doesn't execute it.
TextFileProcessor(java.lang.String inputFile, java.lang.String outputFile)
          Constructs a simple pass, but doesn't execute it.
 
Method Summary
 void doPass()
          Does the general work of a pass.
 void finalizePass()
          Closes all open streams and cleans up after the pass.
 int getLinesRead()
          Returns the number of lines that have been read from the input file.
 java.lang.String nextLine()
          Returns the next line of text from the input source.
 void println(java.lang.String line)
          Sends a line of text to the output file.
 void processLine(java.lang.String lineOfText)
          Takes a line of text and echoes it to the output.
 void setInput(java.io.File theFile)
          Sets the input for this pass to come from the specified file.
 void setInput(java.lang.String filename)
          Sets the input for this pass to come from the specified file.
 void setOutput(java.io.File theFile)
          Sets the output for this pass to go to the specified file.
 void setOutput(java.lang.String filename)
          Sets the output for this pass to go to the specified file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theReader

private java.io.BufferedReader theReader

output

private java.io.PrintWriter output

linesRead

private int linesRead
Constructor Detail

TextFileProcessor

public TextFileProcessor(java.lang.String inputFile,
                         java.lang.String outputFile)
                  throws java.io.FileNotFoundException
Constructs a simple pass, but doesn't execute it.


TextFileProcessor

public TextFileProcessor(java.io.File inputFile,
                         java.io.File outputFile)
                  throws java.io.FileNotFoundException
Constructs a simple pass, but doesn't execute it.

Method Detail

setInput

public void setInput(java.lang.String filename)
              throws java.io.FileNotFoundException
Sets the input for this pass to come from the specified file.

java.io.FileNotFoundException

setInput

public void setInput(java.io.File theFile)
              throws java.io.FileNotFoundException
Sets the input for this pass to come from the specified file.

java.io.FileNotFoundException

setOutput

public void setOutput(java.lang.String filename)
Sets the output for this pass to go to the specified file.


setOutput

public void setOutput(java.io.File theFile)
Sets the output for this pass to go to the specified file.


doPass

public final void doPass()
Does the general work of a pass. Sends each line to the processLine() method, and calls finalizePass() when done.


nextLine

public final java.lang.String nextLine()
Returns the next line of text from the input source.


getLinesRead

public int getLinesRead()
Returns the number of lines that have been read from the input file.


println

public void println(java.lang.String line)
Sends a line of text to the output file.


processLine

public void processLine(java.lang.String lineOfText)
Takes a line of text and echoes it to the output.


finalizePass

public void finalizePass()
Closes all open streams and cleans up after the pass.