Class CompilerIO

java.lang.Object
  |
  +--CompilerIO

public class CompilerIO
extends Object

This class handles all IO for the compiler application.


Field Summary
private  PrintWriter asm
           
private  boolean echoing
           
private  String echoPrefix
           
private  BufferedReader src
           
 
Constructor Summary
CompilerIO(String inFile)
          Create a new CompilerIO object, using the file name given for the input file, and creating the output file name based on the input file name.
CompilerIO(String inFile, String outFile)
          Create a new CompilerIO object, using the two file names given.
 
Method Summary
 void close()
          Close the input and output streams.
 boolean getEchoing()
          Get the echoing property.
 String getEchoPrefix()
          Get the echo prefix string.
static void main(String[] arg)
          Run a simple test of this CompilerIO class.
 void printAsmLine(String s)
          Write a string out to the output file.
 String readSrcLine()
          Read one line of input from the originally specified input file.
 void setEchoing(boolean e)
          Set the echoing property.
 void setEchoPrefix(String s)
          Set the echo prefix that is written out before each echoed line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

src

private BufferedReader src

asm

private PrintWriter asm

echoing

private boolean echoing

echoPrefix

private String echoPrefix
Constructor Detail

CompilerIO

public CompilerIO(String inFile,
                  String outFile)
           throws IOException
Create a new CompilerIO object, using the two file names given.

Parameters:
inFile - the name of the input file
outFile - the name of the output file
Throws:
IOException - If any input or output exception occurs while opening the files.

CompilerIO

public CompilerIO(String inFile)
           throws IOException
Create a new CompilerIO object, using the file name given for the input file, and creating the output file name based on the input file name. The extension is removed from the input file name, and replaced with the string "asm".

Parameters:
inFile - the name of the input file
Throws:
IOException - If any input or output exception occurs while opening the files.
Method Detail

readSrcLine

public String readSrcLine()
                   throws IOException
Read one line of input from the originally specified input file.

Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.
Throws:
IOException - If an I/O error occurs while reading

printAsmLine

public void printAsmLine(String s)
Write a string out to the output file.

Parameters:
s - The String to write out.
Throws:
IOException - If an IO error occurs while writing

setEchoing

public void setEchoing(boolean e)
Set the echoing property. If true, every line read from src stream is copied to asm stream.

Parameters:
e - true or false.

getEchoing

public boolean getEchoing()
Get the echoing property.

Returns:
the current echoing state.

setEchoPrefix

public void setEchoPrefix(String s)
Set the echo prefix that is written out before each echoed line.


getEchoPrefix

public String getEchoPrefix()
Get the echo prefix string.

Returns:
the current value of the echo prefix.

close

public void close()
           throws IOException
Close the input and output streams.

Throws:
IOException - If an I/O error occurs while closing

main

public static void main(String[] arg)
                 throws IOException
Run a simple test of this CompilerIO class.

Parameters:
arg -
[0] pathname to read. If not specified, then the program tries to read "CompilerIO.java".
[1] pathname to write to. If not specified, the CompilerIO constructor is allowed to build the output name from the input name.
Throws:
IOException - If an IO error occurs while processing