Abstract interface for objects that provide read and write access to data. More...
Inherited by BAbstractSocket, BBufferedDataIO, BMemoryRingIO, and BPositionIO.
Public Member Functions | |
BDataIO () | |
This constructor does nothing. | |
virtual | ~BDataIO () |
This destructor does nothing. | |
virtual status_t | Flush () |
Writes pending data to underlying storage. | |
virtual ssize_t | Read (void *buffer, size_t size) |
Reads data from the object into a buffer. | |
status_t | ReadExactly (void *buffer, size_t size, size_t *_bytesRead=NULL) |
Reads an exact amount of data from the object into a buffer. | |
virtual ssize_t | Write (const void *buffer, size_t size) |
Writes data from a buffer to the object. | |
status_t | WriteExactly (const void *buffer, size_t size, size_t *_bytesWritten=NULL) |
Writes an exact amount of data from a buffer to the object. | |
Abstract interface for objects that provide read and write access to data.
The interface provided by this class applies to objects or data that are limited to reading and writing data. Classes derived from this class should re-implement the Read() or the Write() method from this class or both.
Candidates of types of data or objects that should be derived from this class are probably broadcasting media streams (which don't support reading at a certain point in the data) or network streams that output data continuously. Objects and data that support more advanced operations like seeking or reading at writing at defined positions should derive their classes from BPositionIO, which inherits this class.
BDataIO::BDataIO | ( | ) |
This constructor does nothing.
|
virtual |
This destructor does nothing.
|
virtual |
Writes pending data to underlying storage.
This method is relevant for BDataIO implementations that buffer data passed to Write(). The Flush() implementation should make sure that all such data are written to the underlying storage.
The default implementation is a no-op returning B_OK
.
Reimplemented in BBufferedDataIO, and BBufferIO.
|
virtual |
Reads data from the object into a buffer.
Your implementation should copy data into buffer
, with the maximum size of size
.
The default implementation is a no-op returning B_NOT_SUPPORTED
.
Reimplemented in BDatagramSocket, BFile, BBufferedDataIO, BPositionIO, and BMemoryRingIO.
Reads an exact amount of data from the object into a buffer.
This is a convenience wrapper method for Read() for code that expects the exact number of bytes requested to be read. This method calls Read() in a loop to read the data. It fails when Read() returns an error or fails to read any more data (i.e. returns 0).
buffer | Pointer to pre-allocated storage of at least size bytes into which the data shall be read. Won't be dereferenced, when size is 0. |
size | The number of bytes to be read. |
_bytesRead | Optional pointer to a pre-allocated size_t into which the number of bytes actually read will be written. When the method returns B_OK this will always be size. Can be NULL . |
B_OK | All data have been read. |
B_PARTIAL_READ | Read() didn't fail, but couldn't provide as many bytes as requested. |
|
virtual |
Writes data from a buffer to the object.
Your implementation should copy data from buffer
, with the maximum size of size
.
The default implementation is a no-op returning B_NOT_SUPPORTED
.
Reimplemented in BDatagramSocket, BFile, BBufferedDataIO, BPositionIO, and BMemoryRingIO.
Writes an exact amount of data from a buffer to the object.
This is a convenience wrapper method for Write() for code that expects the exact number of bytes given to be written. This method calls Write() in a loop to write the data. It fails when Write() returns an error or fails to write any more data (i.e. returns 0).
buffer | Pointer to a buffer of at least size bytes containing the data to be written. Won't be dereferenced, when size is 0. |
size | The number of bytes to be written. |
_bytesWritten | Optional pointer to a pre-allocated size_t into which the number of bytes actually written will be written. When the method returns B_OK this will always be size. Can be NULL . |
B_OK | All data have been written. |
B_PARTIAL_READ | Write() didn't fail, but couldn't write as many bytes as provided. |