|
||
class RFileBuf : public TStreamBuf;
A stream buffer hosted by a file.
Instances of this class are used by file based persistent stores, i.e. CFileStore
type objects. An RFileBuf object is associated with a file and the file is said to be attached to the stream buffer.
An RFileBuf object is also used by RFileReadStream
and RFileWriteStream
objects to provide buffered file I/O.
The stream buffer has intermediate buffering capabilities.
When used as the basis for a file store, it hosts multiple streams through the TStreamExchange
and RShareBuf
classes.
RFileBuf::Open(RFs &,const TDesC &,TUint)
, RFileBuf::Close()
, RFileBuf::Attach(RFile &,TInt)
, RFileBuf::Detach()
, RFileBuf::File()const
and RFileBuf::Reattach(RFile &)
usage patterns:
Pattern 1: RFileBuf owns the file step 1a: RFileBuf::Open(RFs &,const TDesC &,TUint)
/Create()/Temp() is used to connect the buffer to a file step 1b: Use the file buffer step 1c: RFileBuf::Close()
releases this resource.
Pattern 2: RFile
is opened elsewhere and ownership is handed over to RFileBuf This may happen if the file is already opened by another API,
or from another process for example step 2a: RFileBuf::Attach(RFile &,TInt)
is used to hand ownership of the opened file to the buffer. After RFileBuf::Attach(RFile &,TInt)
the supplied file handle is NULLed. step 2b: Use the file buffer step 2c: RFileBuf::Close()
releases the file resource.
Pattern 3: RFileBuf is used transiently to manage an existing opened file: step 3a: RFileBuf::Attach(RFile &,TInt)
is used to bind the buffer to the already open file. After RFileBuf::Attach(RFile &,TInt)
the supplied file handle is NULLed. step 3b: Use the file buffer step 3c: RFileBuf::File()const
is used to retrieve the file handle again, then RFileBuf::Detach()
is called to disconnect the buffer from the file. At this point, the destruction of the file buffer will have no effect on
the file. The retrieved file handle in step 3c must be used to close the file.
Pattern 4: Transient direct file access to a buffered file step 4a: RFileBuf::File()const
is used to retrieve the file handle. [Optional: RFileBuf::Detach()
is used to disconnect the file buffer] step 4b: Use the file directly. Note that writing to the file may cause coherency
problems with the RFileBuf buffer - in which case you need to RFileBuf::Reset()
the buffer as well. step 4c: [Optional: RFileBuf::Reattach(RFile &)
is used to hand the file back to the buffer]. Use of the buffer is resumed
MStreamBuf
-
A stream buffer that provides a generic I/O interface for streamed data.
TStreamBuf
-
Adds buffering capabilities to a stream buffer
RFileBuf
- A stream buffer hosted by a file. ...
Defined in RFileBuf
:
Attach(RFile &,TInt)
Attaches the specified file to this stream buffer.Close()
Writes any outstanding data from the intermediate buffer before freeing the inte...Create(RFs &,const TDesC &,TUint)
Creates a file with the specified name and attaches it to this stream buffer.Detach()
Detaches the file from this stream buffer.DoReadL(TAny *,TInt)
Reads data from the intermediate buffer into the specified memory location.DoReadL(TDes8 &,TInt,TRequestStatus &)
Reads data from the stream buffer into the specified descriptor.DoRelease()
Frees resources before abandoning the stream buffer.DoSeekL(TMark,TStreamLocation,TInt)
DoSynchL()
Synchronises the stream buffer with the stream, leaving if any error occurs.DoWriteL(const TAny *,TInt)
Writes data from the specified memory location into the intermediate buffer.DoWriteL(const TDesC8 &,TInt,TRequestStatus &)
Writes data from the specified descriptor into this stream buffer.File()const
Gets a reference to the file attached to this stream buffer.Open(RFs &,const TDesC &,TUint)
Opens the specified file and attaches it to this stream buffer.OverflowL()
Empties the intermediate buffer and resets the start and end points of the write...RFileBuf()
Constructs the object with a default intermediate buffer size.RFileBuf(TInt)
Constructs the object with the specified intermediate buffer size.Reattach(RFile &)
Re-attaches the specified file to this stream buffer.Replace(RFs &,const TDesC &,TUint)
Replaces the file with the specified name and attaches it to this stream buffer.Reset()
Frees the intermediate buffer.Reset(TInt)
Frees the intermediate buffer and changes the size of any future intermediate bu...SetBuf(TArea,TUint8 *,TUint8 *)
Sets the start and end points of the read area within the intermediate buffer.SetBuf(TRead,TUint8 *,TUint8 *)
Sets the start and end points of the read area within the intermediate buffer.SetBuf(TWrite,TUint8 *,TUint8 *)
Sets the start and end points of the read area within the intermediate buffer.SetSizeL(TInt)
Changes the size of the file attached to this buffer to the specified value.Temp(RFs &,const TDesC &,TFileName &,TUint)
Creates and opens a temporary file with a unique name and attaches it to this st...UnderflowL(TInt)
Re-fills the intermediate buffer and resets the start and end points of the read...Inherited from MStreamBuf
:
ERead
EWrite
PushL()
Puts a cleanup item for this object onto the cleanup stack.Read(TDes8 &,TInt,TRequestStatus &)
Reads data, asynchronously, from the stream buffer into the specified descriptor...Read(TDes8 &,TRequestStatus &)
Reads data, asynchronously, from the stream buffer into the specified descriptor...ReadL(MStreamInput &)
Reads data from the stream buffer into the specified data sink.ReadL(MStreamInput &,TInt)
Reads data from the stream buffer into the specified data sink.ReadL(MStreamInput &,TStreamTransfer)
Reads data from the stream buffer into the specified data sink.ReadL(TAny *,TInt)
Reads data from the stream buffer into the specified memory location.ReadL(TDes8 &,TInt,TRequestStatus &)
Reads data, asynchronously, from the stream buffer into the specified descriptor...ReadL(TDes8 &,TRequestStatus &)
Reads data, asynchronously, from the stream buffer into the specified descriptor...Release()
Frees resources before abandoning the stream buffer.SeekL(TMark,TStreamLocation,TInt)
Moves the position of the read mark or the write mark in the stream.SeekL(TMark,TStreamPos)
Moves the position of the read or write mark in the stream.SeekL(TRead,TInt)
Moves the position of the read mark in the stream by the specified offset.SeekL(TRead,TStreamLocation,TInt)
Moves the position of the read mark in the stream.SeekL(TWrite,TInt)
Moves the position of the write mark in the stream by the specified offset.SeekL(TWrite,TStreamLocation,TInt)
Moves the position of the write mark in the stream.SizeL()const
Gets the size of the stream.Synch()
Synchronises the stream buffer with the stream, returning any error.SynchL()
Synchronises the stream buffer with the stream, leaving if any error occurs.TMark
Used to identify the type of mark in a stream.TRead
Indicates that an operation applies to the read mark in a stream or to the read ...TWrite
Indicates that an operation applies to the write mark in a stream or to the writ...TellL(TRead)const
Gets the position of the read mark within the stream.TellL(TWrite)const
Gets the position of the write mark within the stream.Write(const TDesC8 &,TInt,TRequestStatus &)
Write(const TDesC8 &,TRequestStatus &)
Writes data, asynchronously, from the specified descriptor into the stream buffe...WriteL(MStreamOutput &)
Writes data into the stream buffer from the specified data source.WriteL(MStreamOutput &,TInt)
Writes data into the stream buffer from the specified data source.WriteL(MStreamOutput &,TStreamTransfer)
Writes data into the stream buffer from the specified data source.WriteL(const TAny *,TInt)
Writes data from the specified memory location into the stream buffer.WriteL(const TDesC8 &,TInt,TRequestStatus &)
Writes data, asynchronously, from the specified descriptor into the stream buffe...WriteL(const TDesC8 &,TRequestStatus &)
Writes data, asynchronously, from the specified descriptor into the stream buffe...Inherited from TStreamBuf
:
Avail(TArea)const
Gets the number of bytes available in the read or write area within the intermed...Avail(TRead)const
Gets the number of bytes available in the read area within the intermediate buff...Avail(TWrite)const
Gets the number of bytes available in the write area within the intermediate buf...DoReadL(MStreamInput &,TStreamTransfer)
Reads data from the intermediate buffer and, if necessary, any remaining data fr...DoWriteL(MStreamOutput &,TStreamTransfer)
End(TArea)const
Gets the current end point of the read or write area within the intermediate buf...End(TRead)const
Gets the current end point of the read area within the intermediate buffer.End(TWrite)const
Gets the current end point of the write area within the intermediate buffer.Ptr(TArea)const
Gets the current start point of the read or write area within the intermediate b...Ptr(TRead)const
Gets the current start point of the read area within the intermediate buffer.Ptr(TWrite)const
Gets the current start point of the write area within the intermediate buffer.SetEnd(TArea,TUint8 *)
SetEnd(TRead,TUint8 *)
SetEnd(TWrite,TUint8 *)
SetPtr(TArea,TUint8 *)
Sets the start point of the read and/or the write area within the intermediate b...SetPtr(TRead,TUint8 *)
Sets the start point of the write area within the intermediate buffer.SetPtr(TWrite,TUint8 *)
Sets the start point of the write area within the intermediate buffer.TArea
Used to identify the type of area within an intermediate buffer.IMPORT_C RFileBuf();
Constructs the object with a default intermediate buffer size.
The size of the intermediate buffer is the value of the constant KDefaultFileBufSize.
IMPORT_C RFileBuf(TInt aSize);
Constructs the object with the specified intermediate buffer size.
If the intermediate buffer size is zero, then the class provides an MStreamBuf
interface to unbuffered file I/O.
|
IMPORT_C void Reset();
Frees the intermediate buffer.
If there is any read data in the intermediate buffer, then the function reverts the read position within the stream.
The intermediate buffer must not contain any outstanding write data, otherwise the function raises a STORE-File 6 panic.
inline void Reset(TInt aSize);
Frees the intermediate buffer and changes the size of any future intermediate buffer to the specified value.
The intermediate buffer must not contain any outstanding write data, otherwise the function raises a STORE-File 6 panic.
|
IMPORT_C TInt Open(RFs &aFs, const TDesC &aName, TUint aFileMode);
Opens the specified file and attaches it to this stream buffer.
If the file cannot be opened, then it is not attached to this stream buffer.
|
|
RFileBuf::Attach(RFile &,TInt)
Attaches the specified file to this stream buffer.IMPORT_C TInt Create(RFs &aFs, const TDesC &aName, TUint aFileMode);
Creates a file with the specified name and attaches it to this stream buffer.
The file must not already exist.
If the file cannot be created and opened, then it is not attached to this stream buffer.
|
|
RFileBuf::Attach(RFile &,TInt)
Attaches the specified file to this stream buffer.IMPORT_C TInt Replace(RFs &aFs, const TDesC &aName, TUint aFileMode);
Replaces the file with the specified name and attaches it to this stream buffer.
If there is an existing file with the same name, then this function overwrites it. If the file does not already exist, it is created.
If the file cannot be replaced, then it is not attached to this stream buffer.
|
|
RFileBuf::Attach(RFile &,TInt)
Attaches the specified file to this stream buffer.IMPORT_C TInt Temp(RFs &aFs, const TDesC &aPath, TFileName &aName, TUint aFileMode);
Creates and opens a temporary file with a unique name and attaches it to this stream buffer.
|
|
RFileBuf::Attach(RFile &,TInt)
Attaches the specified file to this stream buffer.IMPORT_C void Attach(RFile &aFile, TInt aPos=0);
Attaches the specified file to this stream buffer.
The function also re-sets the intermediate buffer's read and write marks to the beginning of the intermediate buffer and sets the read and write stream positions to the specified offset within the file.
|
RFileBuf::Detach()
Detaches the file from this stream buffer.RFileBuf::Reattach(RFile &)
Re-attaches the specified file to this stream buffer.IMPORT_C void Close();
Writes any outstanding data from the intermediate buffer before freeing the intermediate buffer and closing the attached file.
inline void Detach();
Detaches the file from this stream buffer.
The intermediate buffer's read and write marks are not changed, and the stream positions are not changed. This means that the contents of the file should not change while it is detached.
RFileBuf::Attach(RFile &,TInt)
Attaches the specified file to this stream buffer.RFileBuf::Reattach(RFile &)
Re-attaches the specified file to this stream buffer.inline void Reattach(RFile &aFile);
Re-attaches the specified file to this stream buffer.
The intermediate buffer's read and write marks are not changed, and the stream positions are not changed.
The file should be the one that was detached using the RFileBuf::Detach()
function.
|
RFileBuf::Attach(RFile &,TInt)
Attaches the specified file to this stream buffer.RFileBuf::Detach()
Detaches the file from this stream buffer.IMPORT_C void SetSizeL(TInt aSize);
Changes the size of the file attached to this buffer to the specified value.
Writes any outstanding data from the intermediate buffer to the stream hosted by the file. Any data in the intermediate buffer that would lie beyond the end of the truncated file, is not written.
|
inline RFile& File() const;
Gets a reference to the file attached to this stream buffer.
|
protected: IMPORT_C virtual TInt UnderflowL(TInt aMaxLength);
Re-fills the intermediate buffer and resets the start and end points of the read area.
The implementation of this function depends on the way the stream itself is implemented. For example, the in-memory streams have simple implementations.
|
|
protected: IMPORT_C virtual void OverflowL();
Empties the intermediate buffer and resets the start and end points of the write area.
The implementation of this function depends on the way the stream itself is implemented. For example, the in-memory streams have simple implementations.
protected: IMPORT_C virtual void DoRelease();
Frees resources before abandoning the stream buffer.
It is called by MStreamBuf::Release()
.
This implementation is empty, but classes derived from MStreamBuf
can provide their own implementation, if necessary.
MStreamBuf::Release()
Frees resources before abandoning the stream buffer.protected: IMPORT_C virtual void DoSynchL();
Synchronises the stream buffer with the stream, leaving if any error occurs.
In effect, this ensures that buffered data is delivered to the stream.
It is called by MStreamBuf::SynchL()
.
This implementation is empty, but classes derived from MStreamBuf
can provide their own implementation, if necessary.
MStreamBuf::SynchL()
Synchronises the stream buffer with the stream, leaving if any error occurs.protected: IMPORT_C virtual TInt DoReadL(TAny *aPtr, TInt aMaxLength);
Reads data from the intermediate buffer into the specified memory location.
The function calls the virtual function UnderfLowL() to give concrete implementations the chance to refill the intermediate buffer, and satisfy the caller's requirements.
This implementation overrides the one supplied by the base class MStreamBuf
, and is called by, MStreamBuf::ReadL(TAny *,TInt)
.
|
|
MStreamBuf::ReadL(TAny *,TInt)
Reads data from the stream buffer into the specified memory location.MStreamBuf::DoReadL(TAny *,TInt)
protected: IMPORT_C virtual TInt DoReadL(TDes8 &aDes, TInt aMaxLength, TRequestStatus &aStatus);
Reads data from the stream buffer into the specified descriptor.
This function is called by MStreamBuf::ReadL(TDes8 &,TInt,TRequestStatus &)
.
This implementation deals with the request synchronously, and completes the request with KErrNone. Other implementations may choose to deal with this in a true asynchronous manner.
In addition, the read operation itself uses the RFileBuf::DoReadL(TAny *,TInt)
variant.
|
|
MStreamBuf::ReadL(TAny *,TInt)
Reads data from the stream buffer into the specified memory location.protected: IMPORT_C virtual void DoWriteL(const TAny *aPtr, TInt aLength);
Writes data from the specified memory location into the intermediate buffer.
The function calls the virtual function OverfLowL() to give concrete implementations the chance to forward the intermediate buffer content to its destination.
This implementation overrides the one supplied by the base class MStreamBuf
, and is called by MStreamBuf::WriteL(const TAny *,TInt)
.
|
MStreamBuf::WriteL(const TAny *,TInt)
Writes data from the specified memory location into the stream buffer.MStreamBuf::DoWriteL(const TAny *,TInt)
protected: IMPORT_C virtual TInt DoWriteL(const TDesC8 &aDes, TInt aMaxLength, TRequestStatus &aStatus);
Writes data from the specified descriptor into this stream buffer.
This function is called by MStreamBuf::WriteL(const TDesC8 &,TInt,TRequestStatus &)
.
This implementation deals with the request synchronously, and completes the request with KErrNone. Other implementations may choose to deal with this in a true asynchronous manner.
In addition, the write operation itself uses the DoWriteL(TAny*,TInt) variant.
|
|
MStreamBuf::WriteL(const TAny *,TInt)
Writes data from the specified memory location into the stream buffer.protected: IMPORT_C virtual TStreamPos DoSeekL(TMark aMark, TStreamLocation aLocation, TInt anOffset);
|
|
protected: inline void SetBuf(TRead, TUint8 *aPtr, TUint8 *anEnd);
Sets the start and end points of the read area within the intermediate buffer.
|
MStreamBuf::TRead
Indicates that an operation applies to the read mark in a stream or to the read ...TStreamBuf::SetBuf(TArea,TUint8 *,TUint8 *)
Sets the start and end points of the read and/or the write area within the inter...protected: inline void SetBuf(TWrite, TUint8 *aPtr, TUint8 *anEnd);
Sets the start and end points of the read area within the intermediate buffer.
|
MStreamBuf::TWrite
Indicates that an operation applies to the write mark in a stream or to the writ...TStreamBuf::SetBuf(TArea,TUint8 *,TUint8 *)
Sets the start and end points of the read and/or the write area within the inter...protected: inline void SetBuf(TArea anArea, TUint8 *aPtr, TUint8 *anEnd);
Sets the start and end points of the read area within the intermediate buffer.
|
TStreamBuf::SetBuf(TArea,TUint8 *,TUint8 *)
Sets the start and end points of the read and/or the write area within the inter...