Synergy Home Page

au.edu.swin.synergy.lib.io
Class BTextdb

java.lang.Object
  |
  +--au.edu.swin.synergy.lib.io.BTextdb

public class BTextdb
extends Object

This class allows lines of text to be read and written to text files. Comments starting with # are ignored the lines are stripped of leading and trailing white space blank lines are skipped and the resulting lines are returned in the form of a BTextdbRecord see sample test class for details

Author:
John Newbigin
Requirement/analysis/design Reference:
 
Copyright Belongs To:
Synergy Software
See Also:
BTextdbRecord

Constructor Summary
BTextdb()
          Creates a new text db with no file name specified.
BTextdb(String fName)
          Creates a new database object
 
Method Summary
 void addRecord(BTextdbRecord record)
          Write a record to the database
 void close()
          close an open file
 BTextdbRecord getRecord()
          Get a record from the database
 boolean openFileForRead()
          openFileForRead
 boolean openFileForRead(InputStream newInputStream)
          This will use the given input stream as the source of the file to read from.
 boolean openFileForWrite(boolean append)
          opens a file for writing
 boolean openFileForWrite(boolean append, OutputStream newOutputStream)
          opens a file for writing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BTextdb

public BTextdb(String fName)
Creates a new database object
Parameters:
fName - the name of the file

BTextdb

public BTextdb()
Creates a new text db with no file name specified. This assumes that the user will be supplying their own input or output streams.
Method Detail

getRecord

public BTextdbRecord getRecord()
Get a record from the database
Returns:
the record from the database, or null if there are no more records
Pre Condition:
the file has been opened for reading

addRecord

public void addRecord(BTextdbRecord record)
Write a record to the database
Parameters:
record - the record to add
Pre Condition:
the file has been opened for writing

openFileForRead

public boolean openFileForRead()
openFileForRead
Returns:
true if the file could be opened, otherwise false
Post Condition:
the file is opened for reading

openFileForRead

public boolean openFileForRead(InputStream newInputStream)
This will use the given input stream as the source of the file to read from.
Parameters:
inputStream - The input stream to read from

openFileForWrite

public boolean openFileForWrite(boolean append)
opens a file for writing
Parameters:
append - if append is false, then any existing data will be overwritten
Returns:
true if the file could be opened
Post Condition:
the file is opened for writing

openFileForWrite

public boolean openFileForWrite(boolean append,
                                OutputStream newOutputStream)
opens a file for writing
Parameters:
append - if append is false, then any existing data will be overwritten
Returns:
true if the file could be opened
Post Condition:
the file is opened for writing

close

public void close()
close an open file
Pre Condition:
the file is open
Post Condition:
the file is closed

Synergy Home Page