Vault  4.1
Public Member Functions
VBufferedFileStream Class Reference

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>

Inheritance diagram for VBufferedFileStream:
VAbstractFileStream VStream

List of all members.

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.

Detailed Description

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.

See also:
VStream
VAbstractFileStream
VDirectIOFileStream

Definition at line 32 of file vbufferedfilestream.h.


Constructor & Destructor Documentation

VBufferedFileStream::VBufferedFileStream ( const VFSNode node)

Constructs a stream with a node.

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

Parameters:
fthe POSIX file handle
closeOnDestructtrue 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.


Member Function Documentation

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.

Parameters:
fthe POSIX file handle
closeOnDestructtrue 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.

Vs64 VBufferedFileStream::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 85 of file vbufferedfilestream.cpp.

References VFileSystem::fread(), and V_MIN.

Vs64 VBufferedFileStream::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 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.

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

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

Returns:
the current offset

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

Returns:
the number of bytes currently available for reading

Implements VStream.

Definition at line 205 of file vbufferedfilestream.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.