SophiaFramework UNIVERSE 5.3 |
The SFXFile class is used to perform the file operations such as creating a file, moving a file, deleting a file, reading or writing data from or into the file storage with or without the stream, retrieving file attribute information, making a temporary file etc.
Data can be read from /written into the file storage using the SFXFile class as follows:
How to use the SFXFile class
File open mode | |
---|---|
There are two kinds of file open modes: the Read Only mode and the Read Write mode. In case of the file input, open the file in the read only mode with the SFXFile::OpenReadOnly function. In case of the file output, open the file in the Read Write mode with the SFXFile::OpenReadWrite function. |
File pointer | |
---|---|
The SFXFile class has the file pointer. The SFXFile::Read / SFXFile::Write function reads / writes data from / into the file storage through the file pointer, which will advance by the amount of the read / written data. It is possible to move the file pointer with the SFXFile::Seek / SFXFile::SeekStart / SFXFile::SeekEnd. Or, when data is read or written using the stream, the file pointer will advance by the amount of the read / written data too. |
The below is the code to read data from file.
SFCError error; // error value SFXFile file; // SFXFile instance SFXAnsiStringStreamReader reader; // input stream for reading data from file SFXAnsiString stringFromFile; // string to be read from file SFXAnsiString tempString; // open file in ReadOnly mode if ((error = file.OpenReadOnly(SFXPath("/dir1/data.txt"))) == SFERR_NO_ERROR) { // get input stream for reading data from file(buffer size = 1024) if ((error = file.GetStreamReader(1024, &reader)) == SFERR_NO_ERROR) { while ((error == SFERR_NO_ERROR) && !reader.Ends()) { // * repeat the following processing until the end of the file is reached // read data from file to input stream actually // up to 1024 byte of data can be read since buffer size is specified if ((error = reader.Fetch()) == SFERR_NO_ERROR) { // read data from input stream to tempString if ((error = reader.ReadSFXAnsiString(&tempString)) == SFERR_NO_ERROR) { // append tempString onto stringFromFile stringFromFile += tempString; } } } reader.Release(); } file.Close(); } if (error != SFERR_NO_ERROR) { // if an error occurs ... }
The below is the code to write data into file.
SFCError error; // error value SFXFile file; // SFXFile instance SFXAnsiStringStreamWriter writer; // output stream for writing data to file SFXAnsiString string("abcdefghijklmnopqrstuvwxyz"); // data to be written ACharConstPtr p = string.GetBuffer(); // pointer to string ACharConstPtr endOfString = p + string.GetLength(); // end of string SInt32 bufferSize = 1024; // open file in Read/Write mode if ((error = file.OpenReadWrite(SFXPath("/dir1/data.txt"))) == SFERR_NO_ERROR) { // get output stream for writing data into file if ((error = file.GetStreamWriter(bufferSize, &writer)) == SFERR_NO_ERROR) { for (; (error == SFERR_NO_ERROR) && (_p < _endOfString) ; _p += bufferSize) { // write size SInt32 size = (endOfString - p < bufferSize) ? endOfString - p : bufferSize; // write string to output stream if ((error = writer.Write(p, size)) == SFERR_NO_ERROR) { // write data from output stream to file actually error = writer.Flush(); } } writer.Release(); } file.Close(); } if (error != SFERR_NO_ERROR) { // if an error occurs ... }
Storage | Stream | SFXDirectory | SFXPath | File Class
Constructor/Destructor |
---|
SFXFile( Void ) Constructor of the SFXFile class.
|
SFXFile(
SInt32 cache
) Constructor of the SFXFile class.
|
~SFXFile( Void ) Destructor of the SFXFile class.
|
Public Functions | |
---|---|
SFCError |
AsSFBAStream(
SFBAStreamSmpPtr result
)
Convert the SFBFile instance internally managed by this file storage into the SFBAStream instance.
|
SFCError |
AsSFBSource(
SFBSourceSmpPtr result
)
Convert the SFBFile instance internally managed by this file storage into the SFBSource instance.
|
Void |
Cancel( Void ) Cancel the registered callback function.
|
Void |
Close( Void ) Close this file.
|
static SFCError |
Create(
SFXPathConstRef path
, Bool force = false
) Create the specified file.
|
static SFCError |
DeviceFreeSpace(
UInt32Ptr result
) Get the number of free bytes currently available in the file system.
|
static SFCError |
DeviceTotalSpace(
UInt32Ptr result
) Get the total room in the file system.
|
static SFCError |
Exists(
SFXPathConstRef path
, BoolPtr result
) Check whether or not the specified file exists.
|
SInt32 |
GetCacheSize( Void ) Get the cache size for operating this file storage.
|
static SFCError |
GetCreateDate(
SFXPathConstRef path
, SFXDatePtr result
) Get the creation date of the specified file.
|
SFXPathConstRef |
GetFilePath( Void ) Get the file path of this file storage.
|
SFBFileSmpConstRef |
GetSFBFile( Void ) Get the SFBFile instance managed internally by this file storage
|
SFBFileMgrSmpConstRef |
GetSFBFileMgr( Void ) Get the SFBFileMgr instance managed internally by this file storage
|
static SFCError |
GetSize(
SFXPathConstRef path
, UInt32Ptr result
) Get the size of the specified file. [in bytes]
|
SFCError |
GetStreamReader(
UInt32 size
, SFXStreamReaderPtr result
) Get the input stream for reading data from this file.
|
SFCError |
GetStreamReader(
SFXStreamReaderPtr result
) Get the input stream for reading data from this file.
|
SFCError |
GetStreamWriter(
UInt32 size
, SFXStreamWriterPtr result
) Get the output stream for writing data onto this file.
|
SFCError |
GetStreamWriter(
SFXStreamWriterPtr result
) Get the output stream for writing data onto this file.
|
static SFCError |
GetTemporaryPath(
SFXPathConstRef path
, SFXPathPtr result
) Get the temporary file path.
|
static SFCError |
GetUniquePath(
SFXPathConstRef path
, SFXAnsiStringConstRef prefix
, SFXAnsiStringConstRef suffix
, SFXPathPtr result
) Get the unique file path that does not duplicate existing ones.
|
static SFCError |
IsReadOnly(
SFXPathConstRef path
, BoolPtr result
) Check whether or not the specified file is read only.
|
static SFCError |
IsSystem(
SFXPathConstRef path
, BoolPtr result
) Check whether or not the specified file is a system file.
|
SFCError |
OpenReadOnly(
SFXPathConstRef path
) Open this file in read only mode.
|
SFCError |
OpenReadWrite(
SFXPathConstRef path
, Bool force = false
) Open this file in read/write mode.
|
SFCError |
Read(
VoidPtr buffer
, UInt32Ptr size
) Read data from this file storage without input stream.
|
static SFCError |
Remove(
SFXPathConstRef path
) Delete the specified file.
|
static SFCError |
Rename(
SFXPathConstRef from
, SFXPathConstRef to
) Move or rename the specified file.
|
SFCError |
ScheduleRead(
CallbackSPP spp
, VoidPtr reference
) Schedule to read data from this file storage without input stream.
|
SFCError |
ScheduleWrite(
CallbackSPP spp
, VoidPtr reference
) [This function cannot be used now]
|
SFCError |
Seek(
SInt32 distance
)
Move the file pointer by the specified amount
from the current position of this file storage. [in bytes]
|
SFCError |
SeekEnd(
SInt32 distance
)
Move the file pointer by the specified amount
from the end position of this file storage. [in bytes]
|
SFCError |
SeekStart(
SInt32 distance
)
Move the file pointer by the specified amount
from the start position of this file storage. [in bytes]
|
Void |
SetCacheSize(
SInt32 size
) Set the cache size for operating this file storage.
|
UInt32 |
Tell( Void ) Get the current position of the file pointer of this file storage.
|
SFCError |
Truncate(
UInt32 position
) Truncate this file storage at the specified position.
|
SFCError |
Write(
VoidConstPtr buffer
, UInt32Ptr size
) Write data into this file storage without output stream.
|
Types |
---|
CallbackSPP
(inherits from SFXStorage)
Type of the callback function for the Storage class.
|
[ public, explicit ] SFXFile(Void);
[ public, explicit ] SFXFile( SInt32 cache // cache size );
In this constructor, cache size for file operations can be set by specifying the cache argument.
With this setting, file system performance can be tuned.
Note | |
---|---|
When the cache argument is specified, this constructor internally calls the SFBFile::SetCacheSize function. |
[ public, virtual ] ~SFXFile(Void);
This destructor calls the SFXFile::Close function.
Note | |
---|---|
Registered callback functions will be canceled. |
[ public, virtual, const ] SFCError AsSFBAStream( SFBAStreamSmpPtr result // pointer to the SFBAStream instance );
Specify the pointer to the SFBAStream instance.
This function converts the SFBFile instance internally managed by this file storage into the SFBAStream instance.
As a result, a pointer to the SFBAStream instance will be returned into the result argument.
Note | |
---|---|
The contents of the file storage can be handled as the SFBAStream instance. |
[ public, virtual, const ] SFCError AsSFBSource( SFBSourceSmpPtr result // pointer to the SFBSource instance );
Specify the pointer to the SFBSource instance.
This function converts the SFBFile instance internally managed by this file storage into the SFBSource instance.
As a result, a pointer to the SFBSource instance will be returned into the result argument.
Note | |
---|---|
This function internally calls the BREW API ISOURCEUTIL_SourceFromAStream function. |
Note | |
---|---|
The contents of the file storage can be handled as the SFBSource instance. |
SFBFile | SFBSource | BREW API ISOURCEUTIL_SourceFromAStream
[ public, virtual ] Void Cancel(Void);
This function cancels scheduling with the SFXFile::ScheduleRead function.
Concretely, the registered callback functions are canceled.
Note | |
---|---|
This function is called in the SFXFile::Close function. |
[ public ] Void Close(Void);
This function closes this file.
Concretely, this function calls the SFXFile::Cancel function and releases the SFBFile instance that this file internally manages.
Note | |
---|---|
The registered callback functions will be canceled. |
Note | |
---|---|
This function is called in the SFXFile::~SFXFile destructor. |
Tip | |
---|---|
When suspending, resources should be released by calling this function. |
SFXFile file;
...
file.Close(); // close file
SFXFile::Cancel | SFXFile::~SFXFile | SFXFile::Create | SFXFile::OpenReadWrite | SFXFile::OpenReadOnly | SFBFile
[ public, static ] SFCError Create( SFXPathConstRef path // file path Bool force = false // whether or not to create directories recursively );
This function creates the file specified in the path argument.
If the force argument is set to true, the directories which do not exist in the specified path will be created automatically.
Note | |
---|---|
This function calls the SFBFileMgr::OpenFile function internally. |
// create file forcedly // * the parent directories will be automatically created if not exist SFXFile::Create(SFXPath("/dir1/data.txt"), true);
SFBFileMgr::OpenFile | SFXFile::OpenReadOnly | SFXFile::OpenReadWrite | SFXFile::Remove | BREW API IFILEMGR_OpenFile | BREW API IFILEMGR_GetLastError
This function gets the number of free bytes currently available in the file system.
The number of free bytes currently available on file system will be returned to the result argument. [in bytes]
Note | |
---|---|
This function internally calls the SFBFileMgr::GetFreeSpace function. |
Caution | |
---|---|
In case of the Simulator, if the space available is larger than the maximum 32-bit integer value, the maximum value of a 32-bit integer is returned(0xFFFFFFFF). |
UInt32 space;
// get the number of free bytes currently available on file system
SFXFile::DeviceFreeSpace(&space);
SFBFileMgr::GetFreeSpace | SFXFile::DeviceTotalSpace | BREW API IFILE_IFILEMGR_GetFreeSpace | BREW API IFILEMGR_GetLastError
This function gets the total room in the file system.
The the total room in the file system will be returned to the result argument. [in bytes]
Note | |
---|---|
This function internally calls the SFBFileMgr::GetFreeSpace function. |
Caution | |
---|---|
In case of the Simulator, if the total room is larger than the maximum 32-bit integer value, the maximum value of a 32-bit integer is returned(0xFFFFFFFF). |
UInt32 space;
// get the total room in the file system
SFXFile::DeviceTotalSpace(&space);
SFBFileMgr::GetFreeSpace | SFXFile::DeviceFreeSpace | BREW API IFILE_IFILEMGR_GetFreeSpace | BREW API IFILEMGR_GetLastError
[ public, static ] SFCError Exists( SFXPathConstRef path // file path to check BoolPtr result // pointer to the result );
The function checks whether or not the file specified in the path argument exists. The result will be returned to the result argument.
Note | |
---|---|
This function internally calls the SFBFileMgr::Test function. |
Bool b; // return value of the SFXFile::Exists function is of the SFCError type // b: whether or not the specifiled file exists SFXFile::Exists(SFXPath("/dir1/data.txt"), &b); if (b) { // when file exist ... }
SFBFileMgr::Test | SFXFile::IsReadOnly | SFXFile::IsSystem | BREW API IFILEMGR_Test
[ public, const ] SInt32 GetCacheSize(Void);
Cache size for operating this file storage. [in bytes]
This function gets the cache size for operating this file storage, which is set with the SFXFile::SetCacheSize function or the SFXFile::SFXFile constructor. [in bytes]
[ public, static ] SFCError GetCreateDate( SFXPathConstRef path // file path SFXDatePtr result // pointer to the result );
The function gets creation date of the file specified in the path argument, which will be returned to the result argument.
Note | |
---|---|
This function internally calls the SFBFileMgr::GetInfo function. |
SFXDate date; // date // get the creation date of the file SFXFile::GetCreateDate(SFXPath("/dir1/data.txt"), &date);
[ public, const ] SFXPathConstRef GetFilePath(Void);
This function gets the file path of this file storage.
If this file storage is closed, an empty path(return value of the SFXPath::EmptyInstance function) will be returned.
SFXFile file; SFXPath path("/data.txt"); // 1: TRACE("1: %s", file.GetFilePath().Get().GetCString()); if (file.OpenReadOnly(path) == SFERR_NO_ERROR) { // 2: /data.txt TRACE("2: %s", file.GetFilePath().Get().GetCString()); file.Close(); // 3: TRACE("3: %s", file.GetFilePath().Get().GetCString()); }
SFXPath | SFXFile::OpenReadOnly | SFXFile::Close | SFXPath::EmptyInstance
[ public, const ] SFBFileSmpConstRef GetSFBFile(Void);
SFBFile instance managed internally by this file storage.
This function gets the SFBFile instance managed internally by this file storage.
[ public, const ] SFBFileMgrSmpConstRef GetSFBFileMgr(Void);
SFBFileMgr instance managed internally by this file storage.
This function gets the SFBFileMgr instance managed internally by this file storage.
[ public, static ] SFCError GetSize( SFXPathConstRef path // file path UInt32Ptr result // pointer to the result );
The function gets the size of the file specified in the path argument, which will be returned to the result argument.
Note | |
---|---|
This function internally calls the SFBFileMgr::GetInfo function. |
UInt32 size;
SFXFile::GetSize(SFXPath("/dir1/data.txt"), &size); // file size is stored in the size variable
[ public, virtual ] SFCError GetStreamReader( UInt32 size // buffer size SFXStreamReaderPtr result // pointer to the input stream );
[ public, virtual ] SFCError GetStreamReader( SFXStreamReaderPtr result // pointer to the input stream );
This function gets the input stream for reading data from this file.
If the size argument is specified, the buffer size of the input stream will be fixed with the specified value. Otherwise, the buffer size will be variable and the SFXElasticStreamReader class will be used internally.
Tip | |
---|---|
You have to use the SFXBinaryStreamReader, SFXAnsiStringStreamReader, or SFXWideStringStreamReader class for the input stream properly depending on the type of data to be read. |
SFXFile file; SFXAnsiStringStreamReader reader; SFXAnsiString temp; SFXAnsiString string; // variable to store the string data which will be read from the file SFXPath path("/data.txt"); // file name // open the file in the ReadOnly mode if (file.OpenReadOnly(path) == SFERR_NO_ERROR) { // if succeeds // get the input stream for reading data from the file file.GetStreamReader(1024, &reader); // repeat the below until the end of file is reached while (!reader.Ends()) { if (reader.GetReadableSize() == 0) { // read data from the file onto input stream actually reader.Fetch(); } // read data from the input stream to the temp variable reader >> temp; string += temp; } file.Close(); // close the file }
SFXFile::GetStreamWriter | SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader
[ public, virtual ] SFCError GetStreamWriter( UInt32 size // buffer size SFXStreamWriterPtr result // pointer to the output stream );
[ public, virtual ] SFCError GetStreamWriter( SFXStreamWriterPtr result // pointer to the output stream );
This function gets the output stream for writing data onto this file.
If the size argument is specified, the buffer size of the output stream will be fixed with the specified value. Otherwise, the buffer size will be variable and the SFXElasticStreamWriter class will be used internally.
Tip | |
---|---|
You have to use the SFXBinaryStreamWriter, SFXAnsiStringStreamWriter, or SFXWideStringStreamWriter class for the output stream properly depending on the type of data to write. |
SFXFile file; SFXAnsiStringStreamWriter writer; SFXAnsiString string("abcdefg"); // variable to store the string data which will be written into the file, which is initialized with "abcdefg" SFXPath path("/data.txt"); // file name // open the file if (file.OpenReadWrite(path) == SFERR_NO_ERROR) { // when success // get the output stream for writing data into the file file.GetStreamWriter(string.GetLength(), &writer); // write data from the string variable onto output stream writer << string; // write data from the output stream into the file actually writer.Flush(); file.Close(); // close the file }
SFXFile::GetStreamReader | SFXBinaryStreamWriter | SFXAnsiStringStreamWriter | SFXWideStringStreamWriter
[ public, static ] SFCError GetTemporaryPath( SFXPathConstRef path // directory path in which the temporary file will be created SFXPathPtr result // pointer to the temporary file path );
This function gets the temporary file path that does not duplicate existing ones.
Note | |
---|---|
To get the permanent file path which is not temporary one, use the SFXFile::GetUniquePath function. |
Note | |
---|---|
This function internally calls the SFXFile::GetUniquePath function by specifying "sfx" as the prefix argument and "fle.tmp" as the suffix argument. |
SFXPath dir("/");
SFXPath path;
if (SFXFile::GetTemporaryPath(path, &path) == SFERR_NO_ERROR) {
// file path like "/sfx7182CBD4fle.tmp" will be obtained
TRACE("%s", path.Get().GetCString());
}
[ public, static ] SFCError GetUniquePath( SFXPathConstRef path // directory path in which the file will be created SFXAnsiStringConstRef prefix // prefix of file name SFXAnsiStringConstRef suffix // suffix of file name SFXPathPtr result // pointer to the file path );
This function gets the unique file path that does not duplicate existing ones.
Note | |
---|---|
Since the file name is generated using a random number, this function might fail in case many files have already existed. If the file name generated using a random number has already existed, repeat to retry this operation up to 64 times. Nevertheless, in case the file path that does not duplicate existing ones can not be generated, this function will fail and return SFERR_FAILED. |
Tip | |
---|---|
To get the temporary file path which will be deleted soon, use the SFXFile::GetTemporaryPath function. |
SFXPath dir("/");
SFXPath path;
if (SFXFile::GetUniquePath(dir, "sfx", ".dat", &path) == SFERR_NO_ERROR) {
// file path like "/sfx7182CBD4.dat" will be obtained
TRACE("%s", path.Get().GetCString());
}
[ public, static ] SFCError IsReadOnly( SFXPathConstRef path // file path to check BoolPtr result // pointer to the result );
The functionc checks whether or not the file specified in the path argument is read only. The result will be returned to the result argument.
Note | |
---|---|
This function internally calls the SFBFileMgr::GetInfo function. |
Bool b; // return value of isReadOnly function is of SFCError type // b: set by isReadOnly function whether specifiled file is read only or not SFXFile::IsReadOnly(SFXPath("/dir1/data.txt"), &b); if (b) { // when file is read only ... }
SFBFileMgr::GetInfo | SFXFile::Exists | SFXFile::IsSystem | BREW API IFILEMGR_GetInfo | BREW API IFILEMGR_GetLastError
[ public, static ] SFCError IsSystem( SFXPathConstRef path // file path to check BoolPtr result // pointer to the result );
The functionc checks whether or not the file specified in the path argument is a system file. The result will be returned to the result argument.
Note | |
---|---|
This function internally calls the SFBFileMgr::GetInfo function. |
SFBFileMgr::GetInfo | SFXFile::Exists | SFXFile::IsReadOnly | BREW API IFILEMGR_GetInfo | BREW API IFILEMGR_GetLastError
[ public ] SFCError OpenReadOnly( SFXPathConstRef path // file path to open );
This function opens the specified file in read only mode.
Note | |
---|---|
This function internally calls the SFBFileMgr::OpenFile function. |
SFXFile file; // open file in read only mode if (file.OpenReadOnly(SFXPath("/dir1/data.txt")) == SFERR_NO_ERROR) { ... // close file file.Close(); }
SFBFileMgr::OpenFile | SFXFile::Create | SFXFile::OpenReadWrite | BREW API IFILEMGR_OpenFile | BREW API IFILEMGR_GetLastError
[ public ] SFCError OpenReadWrite( SFXPathConstRef path // file path Bool force = false // whether or not to create the file when it does not exist );
This function opens the specified file in read/write mode.
Tip | |
---|---|
If true is specified in the force argument, the specified file will be created when it does not exist. |
Note | |
---|---|
This function internally calls the SFBFileMgr::OpenFile function. |
SFXFile file; // open file in read/write mode if (file.OpenReadWrite(SFXPath("/dir1/data.txt")) == SFERR_NO_ERROR) { ... // close file file.Close(); }
SFBFileMgr::OpenFile | SFXFile::Create | SFXFile::OpenReadOnly | BREW API IFILEMGR_OpenFile | BREW API IFILEMGR_GetLastError
[ public, virtual ] SFCError Read( VoidPtr buffer // buffer to read data UInt32Ptr size // before this function is called: size of the data to be read from the file storage; just after this function is returned: size of the data to be read from the file storage actually );
Specify the buffer to read data.
Before calling this function, specify the buffer size to read data from the file storage. Just after this function is returned, the size of data to be read from the file storage actually will be stored into this argument.
This function reads data from this file without input stream.
*1. If this function returns AEE_STREAM_WOULDBLOCK, it will be necessary to register a callback function with the SFXFile::ScheduleRead function where data will be read with this function.
*2. If this function returns the value other than SFERR_NO_ERROR, the specified callback function will not be called.
Note | |
---|---|
This function internally calls the SFBAStream::Read function. |
Prerequisite | |
---|---|
This file needs to be opened with the SFXFile::OpenReadOnly / SFXFile::OpenReadWrite function before this function is called. |
SFBAStream::Read | SFXFile::OpenReadOnly | SFXFile::OpenReadWrite | SFXFile::ScheduleRead | SFXFile::OpenReadOnly | SFXFile::OpenReadWrite | SFXFile::Seek | SFXFile::Write | BREW API IFILE_Read
[ public, static ] SFCError Remove( SFXPathConstRef path // file path );
This function deletes the file specified in the path argument.
Note | |
---|---|
This function calls the SFBFileMgr::Remove function internally. |
if (SFXFile::Remove(SFXPath("/dir/data.txt")) == SFERR_NO_ERROR) { ... }
SFBFileMgr::Remove | SFXFile::Create | SFXDirectory::Remove | BREW API IFILE_Remove | BREW API IFILEMGR_GetLastError
[ public, static ] SFCError Rename( SFXPathConstRef from // file path before changing SFXPathConstRef to // file path after changing );
This function moves or renames the specified file.
Note | |
---|---|
This function calls the SFBFileMgr::Rename function internally. |
The below is the code to move "data.txt" from the "dir1" directory to the "dir2" directory.
if (SFXFile::Rename(SFXPath("/dir1/data.txt"), SFXPath("/dir2/data.txt")) == SFERR_NO_ERROR) { ... }
The below is the code to rename "data.txt" in the "dir1" directory to "file.txt".
if (SFXFile::Rename(SFXPath("/dir1/data.txt"), SFXPath("/dir1/file.txt")) == SFERR_NO_ERROR) { ... }
[ public, virtual ] SFCError ScheduleRead( CallbackSPP spp // callback function pointer VoidPtr reference // data passed to callback function );
This function schedules to read data from this file storage without input stream.
Concretely, this function registers the callback function that will read data with the SFXFile::Read function. The registered callback function will be called by BREW AEE when it is possible to read data.
The status of this file is "under scheduling to read data" until the callback function is called. And after the callback function is called, it will become the status before calling this function, i.e., "this file is opened".
If you call the SFXFile::Cancel function before the callback function is called, reading data will be canceled and the status will be returned to the status before calling this function, i.e., "this file is opened".
* If the SFXFile::Read function returns AEE_STREAM_WOULDBLOCK, it will be necessary to register a callback function with this function where data will be read with the SFXFile::Read function.
Note | |
---|---|
This function internally calls the SFBAStream::Readable function. |
Prerequisite | |
---|---|
This file needs to be opened with the SFXFile::OpenReadOnly / SFXFile::OpenReadWrite function before this function is called. And if this file has been already scheduled to read data, the SFERR_INVALID_STATE error will be returned. |
class MyClass { SFXFile _file; Void Function(Void); XALLBACK_DECLARE_SFXFILE(_SFXFile_OnRead) }; Void MyClass::Function(Void) { SFXPath path("/dir1/data.txt"); // read file in read only mode if (_file.OpenReadOnly(path) == SFERR_NO_ERROR) { // schedule to read data from file _file.ScheduleRead(XALLBACK_INTERNAL(_SFXFile_OnRead));// register the callback function } } // callback function notified that data can be read XALLBACK_IMPLEMENT_SFXFILE(MyClass, _SFXFile_OnRead, error) { SFXBuffer buffer; UInt32 size; buffer.SetSize(32); // allocate buffer for reading data from file size = buffer.GetSize(); // read data from file to buffer switch (_file.Read(buffer.GetBuffer(), &size)) { case SFERR_NO_ERROR: // display the read data buffer.SetSize(size + 1); buffer[buffer.GetSize() + 1] = '\0'; TRACE("%s", SFXAnsiString(buffer).GetCString()); // schedule to read data from file _file.ScheduleRead(XALLBACK_INTERNAL(_SFXFile_OnRead)); // register the callback function break; case EFILEEOF: _file.Close(); // close file break; case AEE_STREAM_WOULDBLOCK: // schedule to read data from file _file.ScheduleRead(XALLBACK_INTERNAL(_SFXFile_OnRead)); // register the callback function break; } return; }
SFBAStream::Readable | SFXFile::Read | SFXFile::OpenReadOnly | SFXFile::OpenReadWrite | SFXFile::Cancel | BREW API IFILE_Readable
[ public, virtual ] SFCError ScheduleWrite( CallbackSPP spp // callback function pointer VoidPtr reference // data passed to callback function );
Return SFERR_UNSUPPORTED.
This function moves the file pointer by the specified amount from the current position of this file storage. [in bytes]
If the file pointer is moved by the specified amount to point to the position before the start or after the end of this file storage, it will be set to the start or the end respectively.
To move the file pointer backward, set the distance argument to a negative value as the moving amount.
When this file storage is opened in the read only mode, if the file pointer is moved to point to the position before the start or after the end of this file storage, this operation will fail.
When this file storage is opened in the read/write mode, if the file pointer is moved to point to the position after the end of this file storage, this file storage will be expanded to that position. And if the position of file pointer is moved to point to the position before the start of this file storage, this operation will fail.
Note | |
---|---|
This function calls the SFBFile::Seek function internally. |
Prerequisite | |
---|---|
This file storage needs to be opened with the SFXFile::OpenReadOnly / SFXFile::OpenReadWrite function before this function is called. |
SFBFile::Seek | SFXFile::OpenReadOnly | SFXFile::OpenReadWrite | SFXFile::SeekStart | SFXFile::SeekEnd | SFXFile::Tell | BREW API IFILE_Seek | BREW API IFILEMGR_GetLastError
This function moves the file pointer by the specified amount from the end position of this file storage. [in bytes]
If the file pointer is moved by the specified amount to point to the position before the start or after the end of this file storage, it will be set to the start or the end respectively.
To move the file pointer backward, set the distance argument to a negative value as the moving amount.
When this file storage is opened in the read only mode, if the file pointer is moved to point to the position before the start or after the end of this file storage, this operation will fail.
When this file storage is opened in the read/write mode, if the file pointer is moved to point to the position after the end of this file storage, this file storage will be expanded to that position. And if the position of file pointer is moved to point to the position before the start of this file storage, this operation will fail.
Note | |
---|---|
This function calls the SFBFile::Seek function internally. |
Prerequisite | |
---|---|
This file storage needs to be opened with the SFXFile::OpenReadOnly / SFXFile::OpenReadWrite function before this function is called. |
SFBFile::Seek | SFXFile::OpenReadOnly | SFXFile::OpenReadWrite | SFXFile::Seek | SFXFile::SeekStart | SFXFile::Tell | BREW API IFILE_Seek | BREW API IFILEMGR_GetLastError
This function moves the file pointer by the specified amount from the start position of this file storage. [in bytes]
If the file pointer is moved by the specified amount to point to the position before the start or after the end of this file storage, it will be set to the start or the end respectively.
To move the file pointer backward, set the distance argument to a negative value as the moving amount.
When this file storage is opened in the read only mode, if the file pointer is moved to point to the position before the start or after the end of this file storage, this operation will fail.
When this file storage is opened in the read/write mode, if the file pointer is moved to point to the position after the end of this file storage, this file storage will be expanded to that position. And if the position of file pointer is moved to point to the position before the start of this file storage, this operation will fail.
Note | |
---|---|
This function calls the SFBFile::Seek function internally. |
Prerequisite | |
---|---|
This file storage needs to be opened with the SFXFile::OpenReadOnly / SFXFile::OpenReadWrite function before this function is called. |
SFBFile::Seek | SFXFile::OpenReadOnly | SFXFile::OpenReadWrite | SFXFile::Seek | SFXFile::SeekEnd | SFXFile::Tell | BREW API IFILE_Seek | BREW API IFILEMGR_GetLastError
This function sets the cache size for operating this file storage.
With this function, performance tuning for the file operation can be performed.
Note | |
---|---|
This cashe size for operating this file storage can be also set with the SFXFile::SFXFile constructor. |
Note | |
---|---|
This function calls the SFBFile::SetCacheSize function internally. |
SFBFile::SetCacheSize | SFXFile::SFXFile | SFXFile::GetCacheSize | BREW API IFILE_SetCacheSize
[ public, const ] UInt32 Tell(Void);
This function gets the current position of the file pointer of this file storage.
Note | |
---|---|
This function calls the SFBFile::Seek function internally. |
// truncate file at the current position of the file pointer
file.Truncate(file.Tell());
SFBFile::Seek | SFXFile::Seek | SFXFile::SeekStart | SFXFile::SeekEnd | BREW API IFILE_Seek
This function truncates this file storage at the specified position.
Note | |
---|---|
This function calls the SFBFile::Truncate function internally. |
Prerequisite | |
---|---|
This file storage needs to be opened with the SFXFile::OpenReadOnly / SFXFile::OpenReadWrite function before this function is called. |
// truncate file at present position of file pointer
file.Truncate(file.Tell());
SFBFile::Truncate | SFXFile::Seek | SFXFile::SeekStart | SFXFile::SeekEnd | SFXFile::Tell | BREW API IFILE_Truncate | BREW API IFILEMGR_GetLastError
[ public, virtual ] SFCError Write( VoidConstPtr buffer // buffer to write data into UInt32Ptr size // before this function is called: size of the buffer to write data into the file storage; just after this function is returned: size of the data to be written into the file storage actually );
Specify the buffer to write data into.
Before calling this function, specify the size of the buffer to write data into the file storage. Just after this function is returned, the size of data to be written into the file storage actually will be stored into this argument.
This function writes data into this file storage without output stream.
Note | |
---|---|
This function calls the SFBFile::Write function internally. |
Prerequisite | |
---|---|
This file storage needs to be opened with the SFXFile::OpenReadWrite function before this function is called. |
SFBFile::Write | SFXFile::OpenReadWrite | SFXFile::Read | SFXFile::Seek | BREW API IFILE_Write
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |