Class BinaryFile

java.lang.Object
  extended by BinaryFile

public class BinaryFile
extends java.lang.Object


Constructor Summary
BinaryFile(java.lang.String filename, char readOrWrite)
          Binary File constructor.
 
Method Summary
 void close()
          Close the file (works for input and output files).
 boolean EndOfFile()
          Checks to see if we are at the end of a file.
 boolean readBit()
          Read a bit froman input file.
 char readChar()
          Read in the next 8 bits to the input file, and interpret them as a character.
 void writeBit(boolean bit)
          Write a bit to an output file This method is only valid for output files, and will halt execution if called on an input file.
 void writeChar(char c)
          Write a character to an output file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryFile

public BinaryFile(java.lang.String filename,
                  char readOrWrite)
Binary File constructor. Open a file for reading, or create a file for writing. If we create a file, and a file already exists with that name, the old file will be removed.

Parameters:
filename - The name of the file to read from or write to
readOrWrite - 'w' or 'W' for an output file (open for writing), and 'r' or 'R' for an input file (open for reading)
Method Detail

EndOfFile

public boolean EndOfFile()
Checks to see if we are at the end of a file. This method is only valid for input files, calling EndOfFile on an output fill will cause the program to halt execution. (This method should probably really throw an exception instead of halting the program on an error, but I'm trying to make your code a little simplier)

Returns:
True if we are at the end of an input file, and false otherwise

readChar

public char readChar()
Read in the next 8 bits to the input file, and interpret them as a character. This method is only valud for input files, and will halt exection of called on an output file. (This method should probably really throw an exception instead of halting the program on an error, but I'm trying to make your code a little simplier)

Returns:
The next character from an input file

writeChar

public void writeChar(char c)
Write a character to an output file. The 8 bits representing the character are written one at a time to the file. This method is only valid for output files, and will halt execution if called on an input file. (This method should probably really throw an exception instead of halting the program on an error, but I'm trying to make your code a little simplier)

Parameters:
c - The character to write to the output file.

writeBit

public void writeBit(boolean bit)
Write a bit to an output file This method is only valid for output files, and will halt execution if called on an input file. (This method should probably really throw an exception instead of halting the program on an error, but I'm trying to make your code a little simplier)

Parameters:
bit - The bit to write. false writes a 0 and true writes a 1.

readBit

public boolean readBit()
Read a bit froman input file. This method is only valid for input files, and will halt exeuction if called on an output file. (This method should probably really throw an exception instead of halting the program on an error, but I'm trying to make your code a little simplier)

Returns:
The next bit in the input file -- false for 0 and true for 1.

close

public void close()
Close the file (works for input and output files). Output files will not be properly written to disk if this method is not called.