com.slurm.gf
Class GFFile

java.lang.Object
  |
  +--java.io.RandomAccessFile
        |
        +--com.slurm.gf.GFFile

public class GFFile
extends java.io.RandomAccessFile

Utility class for reading data out of a binary file that represents a generic font.

This class extends RandomAccessFile so that it can easily extract the information in the "postamble", which (naturally enough) occurs at the end.


Constructor Summary
GFFile(java.lang.String s)
          Creates a GF file stream to read from the file with the specified name.
 
Method Summary
 boolean eof()
          Tests for end of file.
 PostCommand getPostCommand()
          Reads the (hopefully unique) Post command in this file.
 int readByteAsInt()
          Reads a single byte from the file and returns it as an int.
 Command readCommand()
          Reads a GF opcode and its associated parameters.
 int readFourBytesAsInt()
          Reads four bytes from the file and interprets them as an int.
 int readThreeBytesAsInt()
          Reads three bytes from the file and interprets them as an int.
 int readTwoBytesAsInt()
          Reads two bytes from the file and interprets them as an int.
 
Methods inherited from class java.io.RandomAccessFile
close, getFD, getFilePointer, length, read, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GFFile

public GFFile(java.lang.String s)
       throws java.io.FileNotFoundException
Creates a GF file stream to read from the file with the specified name.
Parameters:
s - the name of the file
Method Detail

eof

public boolean eof()
Tests for end of file. It seems like we should be able to do this just by seeking one more byte and checking for an EOFException, but apparently we have to be trickier.

readByteAsInt

public int readByteAsInt()
Reads a single byte from the file and returns it as an int.
Returns:
the int value of the byte read

readTwoBytesAsInt

public int readTwoBytesAsInt()
Reads two bytes from the file and interprets them as an int.
Returns:
the int value of the two bytes read

readThreeBytesAsInt

public int readThreeBytesAsInt()
Reads three bytes from the file and interprets them as an int.
Returns:
the int value of the three bytes read

readFourBytesAsInt

public int readFourBytesAsInt()
Reads four bytes from the file and interprets them as an int.
Returns:
the int value of the four bytes read

readCommand

public Command readCommand()
                    throws GFFileFormatException
Reads a GF opcode and its associated parameters. This method is basically a big switch based on the opcode, which determines how many more bytes to read and which concrete subclass of Command to stuff them into.
Returns:
a Command object encapsulating the opcode and its parameters
See Also:
Command

getPostCommand

public PostCommand getPostCommand()
                           throws GFFileFormatException
Reads the (hopefully unique) Post command in this file.

The method used is suggested in (module 19 of) the original gftype program:

Returns:
the PostCommand at the end of the file