Vault  4.1
Public Member Functions
VDirectIOFileStream Class Reference

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>

Inheritance diagram for VDirectIOFileStream:
VAbstractFileStream VStream

List of all members.

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.

Detailed Description

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.

See also:
VStream
VAbstractFileStream
VBufferedFileStream

Definition at line 32 of file vdirectiofilestream.h.


Constructor & Destructor Documentation

VDirectIOFileStream::VDirectIOFileStream ( const VFSNode node)

Constructs a stream with a node.

Parameters:
nodethe 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.

Parameters:
fdthe POSIX file descriptor
closeOnDestructtrue 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.


Member Function Documentation

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.

Parameters:
fdthe POSIX file descriptor
closeOnDestructtrue 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().

Vs64 VDirectIOFileStream::read ( Vu8 targetBuffer,
Vs64  numBytesToRead 
) [virtual]

Attempts to read a specified number of bytes from the stream.

Parameters:
targetBufferthe buffer to read into
numBytesToReadthe number of bytes to read
Returns:
the actual number of bytes that could be read

Implements VStream.

Definition at line 83 of file vdirectiofilestream.cpp.

References CONST_S64, VStream::needSizeConversion(), and V_MIN.

Vs64 VDirectIOFileStream::write ( const Vu8 buffer,
Vs64  numBytesToWrite 
) [virtual]

Writes bytes to the stream.

Parameters:
bufferthe buffer containing the data
numBytesToWritethe number of bytes to write to the stream
Returns:
the actual number of bytes written

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.

Parameters:
numBytesToSkipthe 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.

Parameters:
offsetthe offset, meaning depends on whence value
whenceSEEK_SET, SEEK_CUR, or SEEK_END
Returns:
true if the seek was successful

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.

Returns:
the current offset

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).

Returns:
the number of bytes currently available for reading

Implements VStream.

Definition at line 204 of file vdirectiofilestream.cpp.

References getIOOffset(), and seek().


The documentation for this class was generated from the following files:

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.