Inheritance diagram for BBufferIO:

Public Member Functions | |
| BBufferIO (BPositionIO *stream, size_t bufferSize=65536L, bool ownsStream=true) | |
| Initialize a BBufferIO object. | |
| size_t | BufferSize () const |
| Return the size of the internal buffer. | |
| virtual status_t | Flush () |
| Write pending modifications to the stream. | |
| virtual status_t | GetSize (off_t *size) const |
| Get the size of the object or data. | |
| bool | OwnsStream () const |
| Tell if the BBufferIO object "owns" the specified stream. | |
| virtual off_t | Position () const |
| Return the current position in the stream. | |
| void | PrintToStream () const |
| Print the object to stdout. | |
| virtual ssize_t | Read (void *buffer, size_t size) |
| Read data from current position. | |
| virtual ssize_t | ReadAt (off_t pos, void *buffer, size_t size) |
| Read the specified amount of bytes at the given position. | |
| virtual off_t | Seek (off_t position, uint32 seekMode) |
| Set the position in the stream. | |
| void | SetOwnsStream (bool ownsStream) |
Set the owns_stream property of the object. | |
| virtual status_t | SetSize (off_t size) |
| Call the SetSize() function of the assigned BPositionIO stream. | |
| BPositionIO * | Stream () const |
| Return a pointer to the stream specified on construction. | |
| virtual ssize_t | Write (const void *buffer, size_t size) |
| Write data to the current position. | |
| virtual ssize_t | WriteAt (off_t pos, const void *buffer, size_t size) |
| Write the specified amount of bytes at the given position. | |
| virtual | ~BBufferIO () |
| Free the resources allocated by the object. | |
This class differs from other classes derived from BPositionIO in a sense that it does not actually provide an actual entity to be read or written to, but rather acts like a "frontend" to a stream. This class especially comes in handy when working with files that are constantly written and rewritten and where you want do this writing buffered so that the hard disk or the network will not have to be accessed so frequently.
This class works as follows. After constructing a BBufferIO object that you want to be buffered, you can create this object. The constructor takes a stream parameter that points to the object to be buffered. You then use this object as a proxy to the resource you want to read of or write to. As soon as you use ReadAt(), the buffer will be initialised to the contents of the original stream, and subsequent calls to the positions within the buffer will not be routed to the original stream. In the same way WriteAt() will change the data in the buffer, but not in the actual stream. In order to flush the changes to the original stream, use the Flush() method. Deleting the object when you are done with it will also flush the stream and update the original stream.
| BBufferIO::BBufferIO | ( | BPositionIO * | stream, | |
| size_t | bufferSize = 65536L, |
|||
| bool | ownsStream = true | |||
| ) |
Initialize a BBufferIO object.
The constructor will create a buffer of the given size and associate the object with the given BPositionIO stream.
| stream | A pointer to a BPositionIO object. | |
| bufferSize | The size of the buffer that the object will allocate and use. | |
| ownsStream | Specifies if the object will delete the stream on destruction. |
| BBufferIO::~BBufferIO | ( | ) | [virtual] |
Free the resources allocated by the object.
Flush pending changes to the stream and free the allocated memory. If the owns_stream property is true, the destructor also deletes the stream associated with the BBufferIO object.
| size_t BBufferIO::BufferSize | ( | ) | const |
Return the size of the internal buffer.
| status_t BBufferIO::Flush | ( | ) | [virtual] |
Write pending modifications to the stream.
| status_t BPositionIO::GetSize | ( | off_t * | size | ) | const [virtual, inherited] |
Get the size of the object or data.
The default implementation uses Seek() with the SEEK_END flag to determine the size of the buffer. If your data or object has a different way of determining size, reimplement this method.
Please check that NULL is not passed into size if you reimplement it in your class.
| [out] | size | The size of the object is put into this parameter. |
B_OK on success or an error code on error. | bool BBufferIO::OwnsStream | ( | ) | const |
Tell if the BBufferIO object "owns" the specified stream.
| true | The object "owns" the stream and will destroy it upon destruction. | |
| false | The object does not own the stream. |
| off_t BBufferIO::Position | ( | ) | const [virtual] |
Return the current position in the stream.
| B_NO_INIT | The object is not associated with a valid BPositionIO stream. |
Implements BPositionIO.
| ssize_t BPositionIO::Read | ( | void * | buffer, | |
| size_t | size | |||
| ) | [virtual, inherited] |
Read data from current position.
This method is derived from BDataIO. The default implementation reads data from the current position of the cursor, pointed at by Position(). If you require different behaviour, please look at BDataIO::Read() for what is expected of this method.
Implements BDataIO.
| ssize_t BBufferIO::ReadAt | ( | off_t | pos, | |
| void * | buffer, | |||
| size_t | size | |||
| ) | [virtual] |
Read the specified amount of bytes at the given position.
| pos | The offset into the stream where to read. | |
| buffer | A pointer to a buffer where to copy the read data. | |
| size | The amount of bytes to read. |
| B_NO_INIT | The object is not associated with a valid BPositionIO stream. | |
| B_BAD_VALUE | The buffer parameter is not valid. |
Implements BPositionIO.
| off_t BBufferIO::Seek | ( | off_t | position, | |
| uint32 | seekMode | |||
| ) | [virtual] |
Set the position in the stream.
Set the position in the stream where the Read() and Write() functions (inherited from BPositionIO) begin reading and writing. How the position argument is understood depends on the seek_mode flag.
| position | The position where you want to seek. | |
| seekMode | Can have three values:
|
| B_NO_INIT | The object is not associated with a valid BPositionIO stream. |
Implements BPositionIO.
| void BBufferIO::SetOwnsStream | ( | bool | owns_stream | ) |
Set the owns_stream property of the object.
| owns_stream | If you pass true, the object will delete the stream upon destruction, if you pass false it will not. |
| status_t BBufferIO::SetSize | ( | off_t | size | ) | [virtual] |
Call the SetSize() function of the assigned BPositionIO stream.
| size | The new size of the BPositionIO object. |
| B_OK | The stream is resized. | |
| B_NO_INIT | The object is not associated with a valid BPositionIO stream. |
Reimplemented from BPositionIO.
| BPositionIO * BBufferIO::Stream | ( | ) | const |
Return a pointer to the stream specified on construction.
| ssize_t BPositionIO::Write | ( | const void * | buffer, | |
| size_t | size | |||
| ) | [virtual, inherited] |
Write data to the current position.
This method is derived from BDataIO. The default implementation writes data to the current position of the cursor, pointed at by Position(). If you require different behaviour, please look at BDataIO::Write() for what is expected of this method.
Implements BDataIO.
| ssize_t BBufferIO::WriteAt | ( | off_t | pos, | |
| const void * | buffer, | |||
| size_t | size | |||
| ) | [virtual] |
Write the specified amount of bytes at the given position.
| pos | The offset into the stream where to write. | |
| buffer | A pointer to a buffer which contains the data to write. | |
| size | The amount of bytes to write. |
| B_NO_INIT | The object is not associated with a valid BPositionIO stream. | |
| B_BAD_VALUE | The buffer parameter is not valid. |
Implements BPositionIO.