class File
MyCpp::Referenced
MyCpp::Object
MyCpp::File
Derivatives: MyCpp::ArrayFile, MyCpp::AsyncFile, MyCpp::DirectFile

Generic file abstraction.

Methods
virtual unsigned long
read (char *buf, unsigned long len) = 0
Reads a chunk of data at the current position.
virtual unsigned long
write (const char *buf, unsigned long len) = 0
Writes a chunk of data at the current position.
virtual void
seek (long long offset, SeekOrigin origin) = 0
Changes current file position.
virtual long long
tell () = 0
Returns current offset from the beginning of the file.
virtual void
flush () = 0
Flushes the file, forcing any buffered bytes to be written out.
void
fullWrite (const char *buf, unsigned long len)
Writes an exact number of bytes at the current position.
int
readInt (int *result)
Reads an integer at the current file position.
int
readDouble (double *result)
Reads a doble at the current file position.
unsigned long
readLine (char *buf, unsigned long len)
FIXME Document this
read

Reads a chunk of data at the current position.

If more that zero bytes was requested, then at least one byte is guaranteed to be read.

This method should be expected to throw an IOException.

Returns the total number of bytes read into the buffer, or 0 if there is no more data because the end of the file has been reached. Also returns 0 if zero bytes was requested to be read.

virtual unsigned long read (char          *buf,
                            unsigned long  len) = 0
buf :  the buffer into which the data is read.
len :  the maximum number of bytes to read.
write

Writes a chunk of data at the current position.

This method should be expected to throw an IOException.

virtual unsigned long write (const char    *buf,
                             unsigned long  len) = 0
len :  the number of bytes to write.
seek

Changes current file position.

Positioning beyond the end or before the beginning of the file is not allowed.

This method should be expected to throw an IOException.

virtual void seek (long long  offset,
                   SeekOrigin origin) = 0
offset :  an offset to seek by.
origin :  -1 - seek from the beginning of the file. 0 - seek from the current position. 1 - seek from the end of the file (the offset should be negative in this case).
tell

Returns current offset from the beginning of the file.

virtual long long tell () = 0
flush

Flushes the file, forcing any buffered bytes to be written out.

The flush method is expected to write out all pending data and to flush the underlying transport/storage facility, so that all chained File objects get flushed, when the topmost File gets flushed.

This method should be expected to throw an IOException.

virtual void flush () = 0
fullWrite

Writes an exact number of bytes at the current position.

This method operates by calling write method in a loop until the requested portion of data gets fully written to the file.

fullWrite does not support asynchronous files (AsyncFile interface) in asynchoronous mode. The behavior is undefined in this case.

This method should be expected to throw an IOException. More precisely, an IOException will be thrown if either the underlying File object's write method throws an IOException, or if it returns 0 (e.g., if it's an AsyncFile in asynchronous mode, and the file is not ready for writing).

void fullWrite (const char    *buf,
                unsigned long  len)
readInt

Reads an integer at the current file position.

After execution of this method the file position is set just after an integer read. If there was no valid integer, the position is not altered.

This method should be expected to throw an IOException.

Returns 0 on success.
Returns -1, if there is no valid integer at the current position.

int readInt (int *result)
result :  a placeholder for the result, may be NULL.
readDouble

Reads a doble at the current file position.

After execution of this method the file position is set just after a double read. If there was no valid double, the position is not altered.

This method should be expected to throw an IOException.

Returns 0 on success.
Returns -1, if there is no valid double at the current position.

int readDouble (double *result)
result :  a placeholder for the result, may be NULL.
readLine

FIXME Document this

unsigned long readLine (char *buf,
                        unsigned long len)