com.avian.util
Class BirdInputFile

java.lang.Object
  extended by com.avian.util.BirdInputFile

public class BirdInputFile
extends java.lang.Object

Utility object that manages all of the messy details of reading from an input file. Reading from an input file is done one line at a time with the underlying assumption that each line will contain enough information to create a meaningful food object. For example, each line could contain a customer number. The customer number becomes a food object that the next bird eats and uses to look up customer address info, while the next bird looks up current charges for this customer number, etc.


Constructor Summary
BirdInputFile(java.lang.String fileName, java.lang.String action)
          This constructor sets the fileName and the action to take.
BirdInputFile(java.lang.String fileName, java.lang.String action, long offset)
          This constructor sets the fileName, the action, and the offset to use.
 
Method Summary
 void close()
          Closes the input file.
 long getOffset()
          Gets the current offset in the file as a long value
 void open()
          Opens the file specified by fileName.
 java.lang.String readLine(boolean lineAtATime)
          Reads one line of text or one character from the input file, depending on the boolean parameter.
 void setOffset(long offset)
          Sets the current offset in the file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BirdInputFile

public BirdInputFile(java.lang.String fileName,
                     java.lang.String action)
This constructor sets the fileName and the action to take. It also sets the offset to zero, so reading will start at the beginning of the file. This is the constructor that is normally used when first starting to read from a file.

Parameters:
fileName - String that contains the path and file name to write to.
action - String that describes how the file should be opened. The action will usually not equal "Continue" when this constructor is used because this constructor is normally used when reading from the beginning of the file.

BirdInputFile

public BirdInputFile(java.lang.String fileName,
                     java.lang.String action,
                     long offset)
This constructor sets the fileName, the action, and the offset to use. This is the constructor that is normally used when reading needs to begin somewhere other than the beginning of the file, such as when the Continue button is pressed.

Parameters:
fileName - String that contains the path and file name to write to.
action - String that describes how the file should be opened, New or Continue. The action will usually equals "Continue" when this constructor is used because Continue will cause the file to be opened and the BufferedReader will then skip the number of characters held in the offset field before it starts reading.
offset - A long value that sets the point where reading will start in the file. An offset of 0 (zero) will cause reading to start at the beginning of the file.
Method Detail

getOffset

public long getOffset()
Gets the current offset in the file as a long value

Returns:
long number of characters from the beginning of the file

setOffset

public void setOffset(long offset)
Sets the current offset in the file

Parameters:
offset - A long number that sets the point in the file where the next readline will be performed

open

public void open()
Opens the file specified by fileName. If the action for this object is "Continue" then the BufferedReader will skip the offset number of characters into the file.


close

public void close()
Closes the input file.


readLine

public java.lang.String readLine(boolean lineAtATime)
Reads one line of text or one character from the input file, depending on the boolean parameter. If lineAtATime is true, then it will read one line of text from the input file. If it is false, it will read one character from the input file.

A line is terminated by any one of the legal End Of Line makers - linefeed, carriage return, or carriage return + linefeed. This method also updates the offset variable so if this bird is stopped and then continued, the correct starting point can be found. The offset point is updated with the length of the line that was read PLUS 1 to move the point past the End Of Line marker. Which means that if a file is using CR+LF, the offset point will not be correctly calculated.

If it is reading one character at a time, the assumption is that it is reading from a file of numbers, which would typically be a text file full of numbers. Which means that the value that is read will be the ASCII value and not the integer value. If you need the actual integer value, the calling method should convert the ASCII into an int

Parameters:
lineAtATime - sets the behavior of this method and will return a line of text from the file if this parameter is true. Otherwise, it will return a string of length 1 with the number that was read. If a non-numeric character was read then it will return the String "0". I don't know why it MUST read numeric values - that's something that should be handled by the calling app so its something to watch for and fix it later.
Returns:
String that contains the line or char that was read from the input file.