Vault
4.1
|
VDirectIOFileStream is a concrete VStream class that implements stream i/o on a file, using unbuffered i/o APIs (e.g., open/close/read/write). More...
#include <vdirectiofilestream.h>
Public Member Functions | |
VDirectIOFileStream () | |
Constructs an undefined stream (you will have to set it up with a subsequent call to setNode()). | |
VDirectIOFileStream (const VFSNode &node) | |
Constructs a stream with a node. | |
VDirectIOFileStream (int fd, bool closeOnDestruct) | |
Constructs a stream with an already-open standard POSIX file handle. | |
virtual | ~VDirectIOFileStream () |
Destructor, closes the stream if it is open, unless you supplied a POSIX file descriptor and specified closeOnDestruct = FALSE. | |
void | setFile (int fd, 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. |
VDirectIOFileStream is a concrete VStream class that implements stream i/o on a file, using unbuffered i/o APIs (e.g., open/close/read/write).
For buffered i/o (usually a better choice for performance), use VBufferedFileStream.
Definition at line 32 of file vdirectiofilestream.h.
VDirectIOFileStream::VDirectIOFileStream | ( | const VFSNode & | node | ) |
Constructs a stream with a node.
node | the node representing the file |
Definition at line 22 of file vdirectiofilestream.cpp.
VDirectIOFileStream::VDirectIOFileStream | ( | int | fd, |
bool | closeOnDestruct | ||
) |
Constructs a stream with an already-open standard POSIX file handle.
fd | the POSIX file descriptor |
closeOnDestruct | true if you want the fd automatically closed when this object is destructed, false if the caller still owns that responsibility |
Definition at line 29 of file vdirectiofilestream.cpp.
void VDirectIOFileStream::setFile | ( | int | fd, |
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.
fd | the POSIX file descriptor |
closeOnDestruct | true if you want the fd automatically closed when this object is destructed, false if the caller still owns that responsibility |
Definition at line 42 of file vdirectiofilestream.cpp.
void VDirectIOFileStream::openReadOnly | ( | ) | [virtual] |
Opens the file read-only.
Throws a VException if it cannot be opened.
Implements VAbstractFileStream.
Definition at line 47 of file vdirectiofilestream.cpp.
References VAbstractFileStream::_throwIfOpenFailed(), VFSNode::getPath(), VAbstractFileStream::mNode, and VFileSystem::open().
void VDirectIOFileStream::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 53 of file vdirectiofilestream.cpp.
References VAbstractFileStream::_throwIfOpenFailed(), VFSNode::exists(), VFSNode::getPath(), VAbstractFileStream::mNode, and VFileSystem::open().
void VDirectIOFileStream::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 66 of file vdirectiofilestream.cpp.
References VAbstractFileStream::_throwIfOpenFailed(), VFSNode::getPath(), VAbstractFileStream::mNode, and VFileSystem::open().
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 83 of file vdirectiofilestream.cpp.
References CONST_S64, VStream::needSizeConversion(), 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 vdirectiofilestream.cpp.
References VString::chars(), VFSNode::getPath(), VAbstractFileStream::mNode, VStream::needSizeConversion(), and V_MIN.
void VDirectIOFileStream::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 158 of file vdirectiofilestream.cpp.
bool VDirectIOFileStream::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 162 of file vdirectiofilestream.cpp.
References VStream::needSizeConversion(), seek(), and V_MIN.
bool VDirectIOFileStream::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 195 of file vdirectiofilestream.cpp.
References VFileSystem::lseek().
Vs64 VDirectIOFileStream::getIOOffset | ( | ) | const [virtual] |
Returns the current offset in the stream.
For file streams, this is an illegal operation and throws an exception.
Implements VStream.
Definition at line 200 of file vdirectiofilestream.cpp.
References VFileSystem::lseek().
Vs64 VDirectIOFileStream::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 204 of file vdirectiofilestream.cpp.
References getIOOffset(), and seek().