|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.avian.util.BirdInputFile
public class BirdInputFile
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 |
---|
public BirdInputFile(java.lang.String fileName, java.lang.String action)
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.public BirdInputFile(java.lang.String fileName, java.lang.String action, long offset)
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 |
---|
public long getOffset()
public void setOffset(long offset)
offset
- A long number that sets the point in the file where the next readline
will be performedpublic void open()
public void close()
public java.lang.String readLine(boolean lineAtATime)
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
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |