MStreamBuf Class Reference

class MStreamBuf

A stream buffer that provides a generic I/O interface for streamed data.

A stream buffer:

may be buffered or unbuffered

may provide read-only, write-only or read/write capability

may be seekable, or unseekable.

A seekable stream buffer maintains independent read and write pointers, which can be manipulated separately. This is unlike the RFile interface which maintains a single current position in the file. For example, file streams and memory streams are seekable streams, but socket, serial-comms, and filtered streams are not.

Objects of this type are used by the stream interface classes derived from RReadStream and RWriteStream.

The class has no member data.

Derive from this class, if the stream has no intermediate buffering capabilities, otherwise derive from TStreamBuf.

Get a reference to the stream buffer used by a read stream by calling RReadStream::Source(). Get a reference to the stream buffer used by a write stream by calling RWriteStream::Sink()

RReadStream RWriteStream TStreamBuf

Public Member Functions
IMPORT_C voidClose()
IMPORT_C voidPushL()
IMPORT_C TIntRead(TDes8 &, TRequestStatus &)
IMPORT_C TIntRead(TDes8 &, TInt, TRequestStatus &)
TInt ReadL(TAny *, TInt)
IMPORT_C TIntReadL(TDes8 &, TRequestStatus &)
TInt ReadL(TDes8 &, TInt, TRequestStatus &)
TStreamTransfer ReadL(MStreamInput &, TStreamTransfer)
IMPORT_C TIntReadL(MStreamInput &, TInt)
voidReadL(MStreamInput &)
voidRelease()
voidSeekL(TMark, TStreamPos)
TStreamPos SeekL(TMark, TStreamLocation, TInt)
TStreamPos SeekL(TRead, TStreamLocation, TInt)
TStreamPos SeekL(TWrite, TStreamLocation, TInt)
TStreamPos SeekL(TRead, TInt)
TStreamPos SeekL(TWrite, TInt)
TInt SizeL()
IMPORT_C TIntSynch()
voidSynchL()
TStreamPos TellL(TRead)
TStreamPos TellL(TWrite)
IMPORT_C TIntWrite(const TDesC8 &, TRequestStatus &)
IMPORT_C TIntWrite(const TDesC8 &, TInt, TRequestStatus &)
voidWriteL(const TAny *, TInt)
IMPORT_C TIntWriteL(const TDesC8 &, TRequestStatus &)
TInt WriteL(const TDesC8 &, TInt, TRequestStatus &)
TStreamTransfer WriteL(MStreamOutput &, TStreamTransfer)
IMPORT_C TIntWriteL(MStreamOutput &, TInt)
voidWriteL(MStreamOutput &)
Protected Member Functions
MStreamBuf()
Private Member Functions
MStreamBuf(const MStreamBuf &)
IMPORT_C TIntDoReadL(TAny *, TInt)
IMPORT_C TIntDoReadL(TDes8 &, TInt, TRequestStatus &)
IMPORT_C TStreamTransferDoReadL(MStreamInput &, TStreamTransfer)
IMPORT_C voidDoRelease()
IMPORT_C TStreamPosDoSeekL(TMark, TStreamLocation, TInt)
IMPORT_C voidDoSynchL()
IMPORT_C voidDoWriteL(const TAny *, TInt)
IMPORT_C TIntDoWriteL(const TDesC8 &, TInt, TRequestStatus &)
IMPORT_C TStreamTransferDoWriteL(MStreamOutput &, TStreamTransfer)
MStreamBuf &operator=(const MStreamBuf &)
Public Member Enumerations
enumTRead { ERead = 0x01 }
enumTWrite { EWrite = 0x02 }
Public Member Type Definitions
typedef TInt TMark

Constructor & Destructor Documentation

MStreamBuf()

MStreamBuf()[protected, inline]

MStreamBuf(const MStreamBuf &)

MStreamBuf(const MStreamBuf &)[private]

Parameters

const MStreamBuf &

Member Functions Documentation

Close()

IMPORT_C voidClose()

Closes the stream buffer.

This function attempts to synchronise buffered data with the stream before freeing any resources. All errors are ignored.

MStreamBuf::Synch() MStreamBuf::Release()

DoReadL(TAny *, TInt)

IMPORT_C TIntDoReadL(TAny *aPtr,
TIntaMaxLength
)[private, virtual]

Parameters

TAny * aPtr
TInt aMaxLength

DoReadL(TDes8 &, TInt, TRequestStatus &)

IMPORT_C TIntDoReadL(TDes8 &aDes,
TIntaMaxLength,
TRequestStatus &aStatus
)[private, virtual]

Reads data from the stream buffer into the specified descriptor.

This function is called by 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 DoReadL(TAny*,TInt) variant.

MStreamBuf::ReadL()

Parameters

TDes8 & aDesThe target descriptor for the data read from the stream buffer. On return, the length of the descriptor is set to the number of bytes read from the stream buffer.
TInt aMaxLengthThe maximum number of bytes to be read. This value must not be greater than the maximum length of the descriptor, otherwise the function raises a STORE-Stream 2 panic.
TRequestStatus & aStatusThe request status that indicates the completion status of this asynchronous request.

DoReadL(MStreamInput &, TStreamTransfer)

IMPORT_C TStreamTransferDoReadL(MStreamInput &anInput,
TStreamTransferaTransfer
)[private, virtual]

Reads data from the stream into the specified data sink.

It is called by ReadL(MStreamInput&,TStreamTransfer).

This implementation calls the sink's ReadFromL() function, which performs the read (transfer) operation.

This implementation of DoReadL() is called for streams that do not have buffering capabilities, and that are derived directly from this class.

MStreamInput::ReadFromL()

Parameters

MStreamInput & anInputThe target data sink.
TStreamTransfer aTransferA stream transfer object defining the amount of data available to be read.

DoRelease()

IMPORT_C voidDoRelease()[private, virtual]

Frees resources before abandoning the stream buffer.

It is called by Release().

This implementation is empty, but classes derived from MStreamBuf can provide their own implementation, if necessary.

MStreamBuf::Release()

DoSeekL(TMark, TStreamLocation, TInt)

IMPORT_C TStreamPosDoSeekL(TMarkaMark,
TStreamLocationaLocation,
TIntanOffset
)[private, virtual]

Parameters

TMark aMark
TStreamLocation aLocation
TInt anOffset

DoSynchL()

IMPORT_C voidDoSynchL()[private, virtual]

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

This implementation is empty, but classes derived from MStreamBuf can provide their own implementation, if necessary.

MStreamBuf::SynchL()

DoWriteL(const TAny *, TInt)

IMPORT_C voidDoWriteL(const TAny *aPtr,
TIntaLength
)[private, virtual]

Parameters

const TAny * aPtr
TInt aLength

DoWriteL(const TDesC8 &, TInt, TRequestStatus &)

IMPORT_C TIntDoWriteL(const TDesC8 &aDes,
TIntaMaxLength,
TRequestStatus &aStatus
)[private, virtual]

Writes data from the specified descriptor into this stream buffer.

This function is called by 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()

Parameters

const TDesC8 & aDesThe source descriptor for the data to be written into the stream buffer.
TInt aMaxLengthThe number of bytes to be written. This value must not be greater than the maximum length of the descriptor, otherwise the function raises a STORE-Stream 6 panic.
TRequestStatus & aStatusThe request status that indicates the completion status of this asynchronous request.

DoWriteL(MStreamOutput &, TStreamTransfer)

IMPORT_C TStreamTransferDoWriteL(MStreamOutput &anOutput,
TStreamTransferaTransfer
)[private, virtual]

Parameters

MStreamOutput & anOutput
TStreamTransfer aTransfer

PushL()

IMPORT_C voidPushL()

Puts a cleanup item for this object onto the cleanup stack.

This allows allocated resources to be cleaned up if a subsequent leave occurs.

Read(TDes8 &, TRequestStatus &)

IMPORT_C TIntRead(TDes8 &aDes,
TRequestStatus &aStatus
)

Reads data, asynchronously, from the stream buffer into the specified descriptor; request completion is guaranteed, even if request initiation fails.

The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) to implement this behaviour. The maximum number of bytes to be read is the value of the maximum length of the descriptor.

MStreamBuf::DoReadL()

Parameters

TDes8 & aDesThe target descriptor for the data read from the stream buffer.
TRequestStatus & aStatusThe request status that indicates the completion status of this asynchronous request.

Read(TDes8 &, TInt, TRequestStatus &)

IMPORT_C TIntRead(TDes8 &aDes,
TIntaMaxLength,
TRequestStatus &aStatus
)

Reads data, asynchronously, from the stream buffer into the specified descriptor; request completion is guaranteed, even if request initiation fails.

The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) to implement this behaviour.

MStreamBuf::DoReadL()

Parameters

TDes8 & aDesThe target descriptor for the data read from the stream buffer.
TInt aMaxLengthThe maximum number of bytes to be read.
TRequestStatus & aStatusThe request status that indicates the completion status of this asynchronous request.

ReadL(TAny *, TInt)

TInt ReadL(TAny *aPtr,
TIntaMaxLength
)[inline]

Reads data from the stream buffer into the specified memory location.

The function calls the virtual function DoReadL(TAny*,TInt) to implement this behaviour.

MStreamBuf::DoReadL()

Parameters

TAny * aPtrA pointer to the target memory location for the data read from the stream buffer.
TInt aMaxLengthThe maximum number of bytes to be read.

ReadL(TDes8 &, TRequestStatus &)

IMPORT_C TIntReadL(TDes8 &aDes,
TRequestStatus &aStatus
)

Reads data, asynchronously, from the stream buffer into the specified descriptor.

The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) to implement this behaviour. The maximum number of bytes to be read is the maximum length of the descriptor.

If the function leaves, then no read request will have been initiated.

MStreamBuf::DoReadL()

Parameters

TDes8 & aDesThe target descriptor for the data read from the stream buffer.
TRequestStatus & aStatusThe request status that indicates the completion status of this asynchronous request.

ReadL(TDes8 &, TInt, TRequestStatus &)

TInt ReadL(TDes8 &aDes,
TIntaMaxLength,
TRequestStatus &aStatus
)[inline]

Reads data, asynchronously, from the stream buffer into the specified descriptor.

The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) to implement this behaviour.

If the function leaves, then no read request will have been initiated.

MStreamBuf::DoReadL()

Parameters

TDes8 & aDesThe target descriptor for the data read from the stream buffer.
TInt aMaxLengthThe maximum number of bytes to be read.
TRequestStatus & aStatusThe request status that indicates the completion status of this asynchronous request.

ReadL(MStreamInput &, TStreamTransfer)

TStreamTransfer ReadL(MStreamInput &anInput,
TStreamTransferaTransfer
)[inline]

Reads data from the stream buffer into the specified data sink.

The function calls the virtual function DoReadL(MStreamInput&,TStreamTransfer) to implement this behaviour.

Parameters

MStreamInput & anInputThe data sink that is the target for the read operation.
TStreamTransfer aTransferDefines the amount of data available to be read.

ReadL(MStreamInput &, TInt)

IMPORT_C TIntReadL(MStreamInput &anInput,
TIntaMaxLength
)

Reads data from the stream buffer into the specified data sink.

The function uses the virtual function DoReadL(MStreamInput&,TStreamTransfer) to implement this behaviour.

Parameters

MStreamInput & anInputThe data sink which is the target for the read operation.
TInt aMaxLengthThe maximum amount of data available to be read.

ReadL(MStreamInput &)

voidReadL(MStreamInput &anInput)[inline]

Reads data from the stream buffer into the specified data sink.

The function uses the virtual function DoReadL(MStreamInput&,TStreamTransfer) to implement this behaviour.

No explicit limit is placed on the amount of data that can be read.

Parameters

MStreamInput & anInputThe data sink that is the target for the read operation.

Release()

voidRelease()[inline]

Frees resources before abandoning the stream buffer.

The function calls the virtual function DoRelease() to implement this behaviour.

Release() is called by both RReadStream::Release() and RWriteStream::Release().

MStreamBuf::DoRelease() RReadStream::Release() RWriteStream::Release()

SeekL(TMark, TStreamPos)

voidSeekL(TMarkaMark,
TStreamPosaPos
)[inline]

Moves the position of the read or write mark in the stream.

The new position is calculated by adding the specified value to the position of the beginning of the stream.

The function calls virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour. Notes: As there are two current positions, one for the read mark and one for the write mark, it is not valid, in general, to use a single call to SeekL() to move both the read and write marks. Not all streams are seekable.

Parameters

TMark aMarkThe type of mark, i.e. read or write.
TStreamPos aPos

SeekL(TMark, TStreamLocation, TInt)

TStreamPos SeekL(TMarkaMark,
TStreamLocationaLocation,
TIntanOffset = 0
)[inline]

Moves the position of the read mark or the write mark in the stream.

The new position is calculated by adding the specified offset to one of:

the position of the beginning of the stream

the position of the end of the stream

the position of the current read mark or write mark.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

As there are two current positions, one for the read mark and one for the write mark, it is not valid, in general, to use a single call to SeekL() to move both the read and write marks.

Not all streams are seekable.

Parameters

TMark aMarkThe type of mark, i.e read or write.
TStreamLocation aLocationThe location in the stream on which the calculation of the new position is based.
TInt anOffset = 0The offset value.

SeekL(TRead, TStreamLocation, TInt)

TStreamPos SeekL(TRead,
TStreamLocationaLocation,
TIntanOffset = 0
)[inline]

Moves the position of the read mark in the stream.

The new position is calculated by adding the specified offset to one of:

the position of the beginning of the stream

the position of the end of the stream

the position of the current read mark.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Not all streams are seekable.

Parameters

TRead
TStreamLocation aLocationThe location in the stream on which the calculation of the new position is based.
TInt anOffset = 0The offset value.

SeekL(TWrite, TStreamLocation, TInt)

TStreamPos SeekL(TWrite,
TStreamLocationaLocation,
TIntanOffset = 0
)[inline]

Moves the position of the write mark in the stream.

The new position is calculated by adding the specified offset to one of:

the position of the beginning of the stream

the position of the end of the stream

the position of the current write mark.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Not all streams are seekable.

Parameters

TWrite
TStreamLocation aLocationThe location in the stream on which the calculation of the new position is based.
TInt anOffset = 0The offset value.

SeekL(TRead, TInt)

TStreamPos SeekL(TRead,
TIntanOffset
)[inline]

Moves the position of the read mark in the stream by the specified offset.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Not all streams are seekable.

Parameters

TRead
TInt anOffsetThe amount by which the position of the read mark is to be moved relative to the existing position of the read mark.

SeekL(TWrite, TInt)

TStreamPos SeekL(TWrite,
TIntanOffset
)[inline]

Moves the position of the write mark in the stream by the specified offset.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Not all streams are seekable.

Parameters

TWrite
TInt anOffsetThe amount by which the position of the write mark is to be moved relative to the existing position of the write mark.

SizeL()

TInt SizeL()const [inline]

Gets the size of the stream.

Synch()

IMPORT_C TIntSynch()

Synchronises the stream buffer with the stream, returning any error.

In effect, this ensures that buffered data is delivered to the stream.

This function calls SynchL() inside a TRAPD harness and returns the leave code if a leave occurs.

MStreamBuf::SynchL() MStreamBuf::DoSynchL()

SynchL()

voidSynchL()[inline]

Synchronises the stream buffer with the stream, leaving if any error occurs.

In effect, this ensures that buffered data is delivered to the stream.

The function calls the virtual function DoSynchL() to implement this behaviour.

MStreamBuf::DoSynchL()

TellL(TRead)

TStreamPos TellL(TRead)const [inline]

Gets the position of the read mark within the stream.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Parameters

TRead

TellL(TWrite)

TStreamPos TellL(TWrite)const [inline]

Gets the position of the write mark within the stream.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Parameters

TWrite

Write(const TDesC8 &, TRequestStatus &)

IMPORT_C TIntWrite(const TDesC8 &aDes,
TRequestStatus &aStatus
)

Writes data, asynchronously, from the specified descriptor into the stream buffer; request completion is guaranteed, even if request initiation fails.

The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) to implement this behaviour. The maximum number of bytes to be written is the value of the maximum length of the descriptor.

MStreamBuf::DoWriteL()

Parameters

const TDesC8 & aDesThe source descriptor for the data to be written into the stream buffer.
TRequestStatus & aStatusThe request status that indicates the completion status of this asynchronous request.

Write(const TDesC8 &, TInt, TRequestStatus &)

IMPORT_C TIntWrite(const TDesC8 &aDes,
TIntaMaxLength,
TRequestStatus &aStatus
)

Parameters

const TDesC8 & aDes
TInt aMaxLength
TRequestStatus & aStatus

WriteL(const TAny *, TInt)

voidWriteL(const TAny *aPtr,
TIntaLength
)[inline]

Writes data from the specified memory location into the stream buffer.

The function calls the virtual function DoWriteL(TAny*,TInt) to implement this behaviour.

MStreamBuf::DoWriteL()

Parameters

const TAny * aPtrA pointer to the memory location from which data is to be written to the stream buffer.
TInt aLengthThe number of bytes to be written.

WriteL(const TDesC8 &, TRequestStatus &)

IMPORT_C TIntWriteL(const TDesC8 &aDes,
TRequestStatus &aStatus
)

Writes data, asynchronously, from the specified descriptor into the stream buffer.

The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) to implement this behaviour. The maximum number of bytes to be written is the value of the maximum length of the descriptor.

If the function leaves, then no write request will have been initiated.

MStreamBuf::DoWriteL()

Parameters

const TDesC8 & aDesThe source descriptor for the data to be written into the stream buffer.
TRequestStatus & aStatusThe request status that indicates the completion status of this asynchronous request.

WriteL(const TDesC8 &, TInt, TRequestStatus &)

TInt WriteL(const TDesC8 &aDes,
TIntaMaxLength,
TRequestStatus &aStatus
)[inline]

Writes data, asynchronously, from the specified descriptor into the stream buffer.

The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) to implement this behaviour.

If the function leaves, then no write request will have been initiated.

MStreamBuf::DoWriteL()

Parameters

const TDesC8 & aDesThe source descriptor for the data to be written into the stream buffer.
TInt aMaxLengthThe maximum number of bytes to be written.
TRequestStatus & aStatusThe request status that indicates the completion status of this asynchronous request.

WriteL(MStreamOutput &, TStreamTransfer)

TStreamTransfer WriteL(MStreamOutput &anOutput,
TStreamTransferaTransfer
)[inline]

Writes data into the stream buffer from the specified data source.

The function calls the virtual function DoWriteL(MStreamOutput&,TStreamTransfer) to implement this behaviour.

Parameters

MStreamOutput & anOutputThe data source for the write operation.
TStreamTransfer aTransferDefines the amount of data to be pulled from the output stream object.

WriteL(MStreamOutput &, TInt)

IMPORT_C TIntWriteL(MStreamOutput &anOutput,
TIntaMaxLength
)

Writes data into the stream buffer from the specified data source.

The function calls the virtual function DoWriteL(MStreamOutput&,TStreamTransfer) to implement this behaviour.

Parameters

MStreamOutput & anOutputThe data source for the write operation.
TInt aMaxLengthThe maximum amount of data available to be written.

WriteL(MStreamOutput &)

voidWriteL(MStreamOutput &anOutput)[inline]

Writes data into the stream buffer from the specified data source.

The function calls the virtual function DoWriteL(MStreamOutput&,TStreamTransfer) to implement this behaviour.

No explicit limit is placed on the amount of data that can be written.

Parameters

MStreamOutput & anOutputThe data source for the write operation.

operator=(const MStreamBuf &)

MStreamBuf &operator=(const MStreamBuf &)[private]

Parameters

const MStreamBuf &

Member Enumerations Documentation

Enum TRead

Indicates that an operation applies to the read mark in a stream or to the read area in an stream buffer.

Enumerators

ERead = 0x01

Enum TWrite

Indicates that an operation applies to the write mark in a stream or to the write area in an stream buffer.

Enumerators

EWrite = 0x02

Member Type Definitions Documentation

Typedef TMark

typedef TInt TMark

Used to identify the type of mark in a stream.

The type is used by functions of this class and derived classes that perform seek operations to marks within a stream.

The type uses the ERead and EWrite enumeration values, as bit flags, to identify the read and write marks respectively.

ERead is an MStreamBuf::TRead enumerator. EWrite is an MStreamBuf::EWrite enumerator.

MStreamBuf::TRead MStreamBuf::TWrite