#include <miodevice.h>
Inheritance diagram for File:
Public Methods | |
File (FILE *str=stdout) | |
File (const String &name, int mode=0) throw (open_failure) | |
bool | exists () const throw (system_failure) |
bool | remove () |
virtual bool | open (int mode) |
virtual void | close () |
virtual void | flush () |
virtual uint | size () const |
virtual int | at () const |
virtual bool | seek (int position) |
virtual bool | atEnd () const |
virtual int | readBlock (char *data, uint len) throw (device_not_open) |
virtual int | readLine (char *data, uint maxlen) throw (device_not_open) |
int | readLine (String &str, int maxlen=-1) throw (device_not_open) |
virtual int | writeBlock (const char *data, uint len) throw (device_not_open) |
virtual int | getch () throw (device_not_open) |
virtual void | putch (char) throw (device_not_open) |
virtual void | ungetch (char) throw (device_not_open) |
@example
File myfile ("myfile.txt", IO_Readable); String linebuf; while (!in.atEnd()) { in.readLine (linebuf); sout << linebuf; }
For streamed interface, you can attach the file device to a stream.
Definition at line 188 of file miodevice.h.
|
Standard constructor for File objects. It is assumed that the FILE stream is already opened.
Definition at line 351 of file miodevice.cc. |
|
Constructor. Creates a File object, and opens it if the mode parameter is given. If the mode parameter is not given, the file can be opened later, or the object can be used to perform also other tasks on the file, such as deletion, etc.
Definition at line 370 of file miodevice.cc. References MagiC::i18n(), IO_Readable, and IO_Writable. |
|
Returns the current position in device. Only meaningful for "block devices", which have a defined size. Reimplemented from IODevice. Definition at line 527 of file miodevice.cc. References MagiC::i18n(). |
|
Returns true if currently at end of file, and false if not.
Reimplemented from IODevice. Definition at line 558 of file miodevice.cc. |
|
Closes the device. Flushes open buffers. Reimplemented from IODevice. Definition at line 478 of file miodevice.cc. References MagiC::i18n(), and IO_Open. Referenced by open(). |
|
Returns true if the file exists.
Definition at line 398 of file miodevice.cc. References MagiC::i18n(). |
|
Flushes (writes) the buffers. Flushing ensures that all data that has been written to the device is really written, and does not wait in a buffer. This is important if an application crashes unexpectedly, or if we just want to be able to read it immediately. This has only effect if the device has been opened for buffered writing. Reimplemented from IODevice. Definition at line 500 of file miodevice.cc. References MagiC::i18n(). |
|
Reads and returns one character from device.
Reimplemented from IODevice. Definition at line 655 of file miodevice.cc. References MagiC::i18n(), and IO_EOS. |
|
Opens device with given I/O mode. Typical usage: File myFile ("/path/file.ext"); myFile.open (IO_Readable); String myFileContents = myFile.readAll (); myFile.close ();
Reimplemented from IODevice. Definition at line 434 of file miodevice.cc. References close(), MagiC::i18n(), and String::isEmpty(). |
|
Writes one character to device.
Reimplemented from IODevice. Definition at line 676 of file miodevice.cc. References MagiC::i18n(). |
|
Reads a data block of a given length to a buffer. The buffer must be allocated to contain the given length of bytes.
Reimplemented from IODevice. Definition at line 572 of file miodevice.cc. References IO_EOS. |
|
Reads a newline-terminated line to a buffer. The buffer is grown as needed, so the maxlen parameter can be much greater than the allocated length of the buffer.
Definition at line 616 of file miodevice.cc. References MagiC::i18n(), and IO_EOS. |
|
Reads a newline (\n) terminated line from device. The buffer must be allocated to contain the given length of bytes. The function spares one byte for the terminating zero, so the actual maximum number of bytes read is one less than the maxlen parameter. Example: // Read in chunks char buffer [1024]; int bytesRead = 0; int totalRead = 0; while (bytesRead = mpDevice->readLine (buffer, 1024)) { linebuf.append (buffer); totalRead += bytesRead; }
Reimplemented from IODevice. Definition at line 592 of file miodevice.cc. References IO_EOS. |
|
Removes a file or directory from the filesystem.
Definition at line 422 of file miodevice.cc. |
|
Changes the current position in device. The function has meaning only if the device is capable of direct access.
Reimplemented from IODevice. Definition at line 543 of file miodevice.cc. References MagiC::i18n(). |
|
Returns the size of the file.
Reimplemented from IODevice. Definition at line 510 of file miodevice.cc. References MagiC::i18n(). |
|
Ungets the last character read from the device.
Reimplemented from IODevice. Definition at line 692 of file miodevice.cc. References MagiC::i18n(), and IO_EOS. |
|
Reads a block of data to file.
Reimplemented from IODevice. Definition at line 639 of file miodevice.cc. References MagiC::i18n(). |