![]() |
Vault
4.1
|
VBufferedFileStream is a concrete VStream class that implements stream i/o on a file, using buffered i/o APIs (e.g., fopen/fclose/fread/fwrite). More...
#include <vbufferedfilestream.h>
Public Member Functions | |
| VBufferedFileStream () | |
| Constructs an undefined stream (you will have to set it up with a subsequent call to setNode()). | |
| VBufferedFileStream (const VFSNode &node) | |
| Constructs a stream with a node. | |
| VBufferedFileStream (FILE *f, bool closeOnDestruct) | |
| Constructs a stream with an already-open standard POSIX file handle. | |
| virtual | ~VBufferedFileStream () |
| Destructor, closes the stream if it is open, unless you supplied a POSIX FILE handle and specified closeOnDestruct = FALSE. | |
| void | setFile (FILE *f, bool closeOnDestruct) |
| Sets the file to an already-open standard POSIX file handle, so that you can use the empty constructor, and call this method after construction; don't call an open method if you use this. | |
| virtual void | openReadOnly () |
| Opens the file read-only. | |
| virtual void | openReadWrite () |
| Opens the file read-write, creating the file if it does not exist. | |
| virtual void | openWrite () |
| Opens the file for writing, creating the file if it does not exist. | |
| virtual bool | isOpen () const |
| Returns true if the file stream is open. | |
| virtual void | close () |
| Closes the file stream. | |
| virtual Vs64 | read (Vu8 *targetBuffer, Vs64 numBytesToRead) |
| Attempts to read a specified number of bytes from the stream. | |
| virtual Vs64 | write (const Vu8 *buffer, Vs64 numBytesToWrite) |
| Writes bytes to the stream. | |
| virtual void | flush () |
| Flushes any pending or buffered write data to the stream. | |
| virtual bool | skip (Vs64 numBytesToSkip) |
| Skips forward in the stream a specified number of bytes. | |
| virtual bool | seek (Vs64 offset, int whence) |
| Seeks in the stream using Unix seek() semantics. | |
| virtual Vs64 | getIOOffset () const |
| Returns the current offset in the stream. | |
| virtual Vs64 | available () const |
| Returns the number of bytes that are available to be read from this stream. | |
VBufferedFileStream is a concrete VStream class that implements stream i/o on a file, using buffered i/o APIs (e.g., fopen/fclose/fread/fwrite).
For unbuffered i/o (usually not as good for performance, but occasionally useful due to lack of buffering), use VDirectIOFileStream.
Definition at line 32 of file vbufferedfilestream.h.
| VBufferedFileStream::VBufferedFileStream | ( | const VFSNode & | node | ) |
Constructs a stream with a node.
| node | the node representing the file |
Definition at line 22 of file vbufferedfilestream.cpp.
| VBufferedFileStream::VBufferedFileStream | ( | FILE * | f, |
| bool | closeOnDestruct | ||
| ) |
Constructs a stream with an already-open standard POSIX file handle.
| f | the POSIX file handle |
| closeOnDestruct | true if you want the FILE automatically closed when this object is destructed, false if the caller still owns that responsibility |
Definition at line 29 of file vbufferedfilestream.cpp.
| void VBufferedFileStream::setFile | ( | FILE * | f, |
| bool | closeOnDestruct | ||
| ) |
Sets the file to an already-open standard POSIX file handle, so that you can use the empty constructor, and call this method after construction; don't call an open method if you use this.
| f | the POSIX file handle |
| closeOnDestruct | true if you want the FILE automatically closed when this object is destructed, false if the caller still owns that responsibility |
Definition at line 44 of file vbufferedfilestream.cpp.
| void VBufferedFileStream::openReadOnly | ( | ) | [virtual] |
Opens the file read-only.
Throws a VException if it cannot be opened.
Implements VAbstractFileStream.
Definition at line 49 of file vbufferedfilestream.cpp.
References VAbstractFileStream::_throwIfOpenFailed(), VFileSystem::fopen(), VFSNode::getPath(), and VAbstractFileStream::mNode.
| void VBufferedFileStream::openReadWrite | ( | ) | [virtual] |
Opens the file read-write, creating the file if it does not exist.
Throws a VException if it cannot be opened.
Implements VAbstractFileStream.
Definition at line 55 of file vbufferedfilestream.cpp.
References VAbstractFileStream::_throwIfOpenFailed(), VFSNode::exists(), VFileSystem::fopen(), VFSNode::getPath(), and VAbstractFileStream::mNode.
| void VBufferedFileStream::openWrite | ( | ) | [virtual] |
Opens the file for writing, creating the file if it does not exist.
Throws a VException if it cannot be opened.
Implements VAbstractFileStream.
Definition at line 68 of file vbufferedfilestream.cpp.
References VAbstractFileStream::_throwIfOpenFailed(), VFileSystem::fopen(), VFSNode::getPath(), and VAbstractFileStream::mNode.
Attempts to read a specified number of bytes from the stream.
| targetBuffer | the buffer to read into |
| numBytesToRead | the number of bytes to read |
Implements VStream.
Definition at line 85 of file vbufferedfilestream.cpp.
References VFileSystem::fread(), and V_MIN.
Writes bytes to the stream.
| buffer | the buffer containing the data |
| numBytesToWrite | the number of bytes to write to the stream |
Implements VStream.
Definition at line 117 of file vbufferedfilestream.cpp.
References VString::chars(), VFileSystem::fwrite(), VFSNode::getPath(), VAbstractFileStream::mNode, VStream::needSizeConversion(), and V_MIN.
| void VBufferedFileStream::flush | ( | ) | [virtual] |
Flushes any pending or buffered write data to the stream.
Until you call flush, you cannot guarantee that your data has actually been written to the underlying physical stream.
Implements VStream.
Definition at line 156 of file vbufferedfilestream.cpp.
References VString::chars(), VFileSystem::fflush(), VFSNode::getPath(), and VAbstractFileStream::mNode.
| bool VBufferedFileStream::skip | ( | Vs64 | numBytesToSkip | ) | [virtual] |
Skips forward in the stream a specified number of bytes.
For memory and file streams, this means advancing the i/o offset by the specified number of bytes; for socket streams, this means reading and discarding the specified number of bytes.
| numBytesToSkip | the number of bytes to skip |
Implements VStream.
Definition at line 166 of file vbufferedfilestream.cpp.
References VStream::needSizeConversion(), seek(), and V_MIN.
| bool VBufferedFileStream::seek | ( | Vs64 | offset, |
| int | whence | ||
| ) | [virtual] |
Seeks in the stream using Unix seek() semantics.
| offset | the offset, meaning depends on whence value |
| whence | SEEK_SET, SEEK_CUR, or SEEK_END |
Implements VStream.
Definition at line 196 of file vbufferedfilestream.cpp.
References VFileSystem::fseek().
| Vs64 VBufferedFileStream::getIOOffset | ( | ) | const [virtual] |
Returns the current offset in the stream.
For file streams, this is the same as the i/o mark.
Implements VStream.
Definition at line 201 of file vbufferedfilestream.cpp.
References VFileSystem::ftell().
| Vs64 VBufferedFileStream::available | ( | ) | const [virtual] |
Returns the number of bytes that are available to be read from this stream.
For file and memory streams, this means the number of bytes from the current i/o mark until the end of the file or buffer. For socket streams, this means the number of bytes that can be read without blocking (that is, the number of bytes that are waiting to be read on the socket at this time).
Implements VStream.
Definition at line 205 of file vbufferedfilestream.cpp.
References getIOOffset(), and seek().