MgByteReader Class Reference
[MgByteReader]
Inherits MgSerializable.
Detailed Description
Reads data from a byte source. Once read, the data in the reader cannot be reread.
- Remarks:
- Here are a few scenarios to illustrate how MgByteSink, MgByteSource and MgByteReader interact:
Loading the content of a file and creating a byte reader to be passed to a service API:
- Create a MgByteSource passing the file name to its constructor
- Get a MgByteReader from this byte source using MgByteSource::GetReader() and pass the obtained reference to the service API</li
Receiving a byte reader from a service API and saving the result into a file:- Create a MgByteSink object passing the MgByteReader reference to its constructor
- Call the method ToFile() on the MgByteSink object.
Saving the content of a memory buffer (or of a string) into a file:- Create a MgByteSource object passing to its constructor the buffer and the number of bytes in this buffer
- Get a MgByteReader from this byte source using MgByteSource::GetReader()
- Create a MgByteSink object passing the MgByteReader reference to its constructor
- Call the method ToFile() on the MgByteSink object.
Public Member Functions | |
virtual INT64 | GetLength () |
Returns the remaining length of the underlying byte source. This length is adjusted for previous reads. If the returned length is zero then the underlying source may be a streaming format and the length is not known. | |
STRING | GetMimeType () |
Gets the mime type of the data in this reader. See MgMimeType for list of possible mime types. | |
bool | IsRewindable () |
Determines if the reader is rewindable. | |
MgByteReader (BYTE_ARRAY_IN contents, INT32 length, CREFSTRING mimeType) | |
Creates a byte reader from an array of bytes. | |
MgByteReader (CREFSTRING contents, CREFSTRING mimeType) | |
Creates a byte reader from a string. | |
MgByteReader (CREFSTRING fileName, CREFSTRING mimeType, bool removeFile) | |
Creates a byte reader from a file. | |
INT32 | Read (BYTE_ARRAY_OUT buffer, INT32 length) |
Reads a buffer. | |
void | Rewind () |
Rewinds to the start of the reader. Depending on the source of the reader, Rewind may not be supported. Readers sourced from true streams cannot be rewound. | |
void | ToFile (CREFSTRING fileName) |
Writes the the contents of the reader to a file. | |
STRING | ToString () |
Friends | |
class | MgByteSink |
class | MgByteSource |