com.billpringle.utils.wrputils
Class WrpBuildZipCodes.ZipFileReader

java.lang.Object
  extended by com.billpringle.utils.wrputils.WrpBuildZipCodes.ZipFileReader
Enclosing class:
WrpBuildZipCodes

 class WrpBuildZipCodes.ZipFileReader
extends java.lang.Object

Class to read the input USPS City/State National zip code text file. This class reads the input zip code text file, which consists of fixed-length records without any end of line sequence. The actual format of this file is described in class WrpBuildZipCodes.

This class will read only the detailed zip code records.

Author:
Bill Pringle

Field Summary
 java.lang.String errMsg
          the most recent error message
protected  java.io.FileReader rdr
          input file reader
 
Constructor Summary
WrpBuildZipCodes.ZipFileReader()
          Default constructor.
WrpBuildZipCodes.ZipFileReader(java.io.File file)
          Constructor with the input file object.
WrpBuildZipCodes.ZipFileReader(java.lang.String fname)
          Constructor with input file name.
 
Method Summary
 void close()
          Close the input file reader.
 java.lang.String getErrorMessage()
          Return the latest error message (if any).
 boolean isOpen()
          Test to see if the input file is currently open.
 WrpZipCode nextFileZip(java.io.FileReader rdr)
          Read the next detailed zip code line from the raw input file.
 boolean openFile(java.lang.String fname)
          Open the specified input text file.
 WrpZipCode readLine()
          Read the next line from the input file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rdr

protected java.io.FileReader rdr
input file reader


errMsg

public java.lang.String errMsg
the most recent error message

Constructor Detail

WrpBuildZipCodes.ZipFileReader

public WrpBuildZipCodes.ZipFileReader()
Default constructor. If this constructor is called, then the input file must be set using the method.


WrpBuildZipCodes.ZipFileReader

public WrpBuildZipCodes.ZipFileReader(java.lang.String fname)
Constructor with input file name. This constructor opens the specified input file. If the file is not found, the error messasge is set.

Parameters:
fname - the name of the USPS input text file

WrpBuildZipCodes.ZipFileReader

public WrpBuildZipCodes.ZipFileReader(java.io.File file)
Constructor with the input file object. This method opens the input file as a FileReader. If the file is not found, the error message is set.

Parameters:
file - the input file object for the USPS text file
Method Detail

openFile

public boolean openFile(java.lang.String fname)
Open the specified input text file. This method opens the specified USPS input text file, returning the status of the open.

Parameters:
fname - the name of the USPS input City/State text file
Returns:
true if the file is opened; false on error

isOpen

public boolean isOpen()
Test to see if the input file is currently open. This method returns the status of the input file. When the input file is closed, the file object is set to null in the close method.

Returns:
true if the file is open; false otherwise

readLine

public WrpZipCode readLine()
Read the next line from the input file. This method returns the next detailed record. It will test to determine if the input file is open. If so, it will read the next zip code detail record. If no detail records remain, the method will return null.

Returns:
the next zip code in input file, or false if none remain

nextFileZip

public WrpZipCode nextFileZip(java.io.FileReader rdr)
Read the next detailed zip code line from the raw input file. Since the input text file contains fixed-length records without any end of line sequence, we must read a fixed number of characters and then parse the result.

Parameters:
rdr - a file reader opened to the raw citystate.txt input file
Returns:
a zip code object containing the information from the input line

getErrorMessage

public java.lang.String getErrorMessage()
Return the latest error message (if any). This method will return the latest error message and reset the message to null.

Returns:
the current error message (possibly null)

close

public void close()
           throws java.io.IOException
Close the input file reader. This method will return the current input file object and free any memory associated with the instance.

Throws:
java.io.IOException