An ArrayOutputRecordStream object represents an array of Record objects opened for sequential write access. The array is created implicitly when it is opened (see "Opening and closing") and expands with the data written into it.
The ArrayOutputRecordStream class offers methods for reading records. When writing, records are always added at the end of the array. In addition, this class also offers methods to fetch the entire contents of the data stream, to delete the contents, or to inquire the size.
Opening and closing
When an ArrayOutputRecordStream object is constructed, an array is provided internally into which records are later to be written. When doing this, the calling program can specify how many records the array should initially receive. If it does not do this, a default size is assumed. However, if this size is not sufficient to accommodate the records, the array is automatically enlarged internally.
The close() method is present, but has no function.
Methods for writing records
The write() method adds a record after the last record in the array.
The flush() method is present, but has no function for this class.
Methods for access to the content of a data stream
The size() method returns the number of records in the array.
The reset() method enables the entire contents of the array to be deleted. The array itself is retained unchanged in size and is refilled when further write() calls are made.
The toRecordArray() method returns the entire current contents of the data stream as an array of Record objects. The array returned is, in contrast to the one used internally, of exactly the size required to contain the data. The individual records are not copied here, which means that manipulation of the record contents has an effect on the content of the data stream.
The writeTo() method writes the entire current contents of the data stream into another specified data stream. Every data stream whose implementation is derived from the abstract class OutputRecordStream is suitable for this.