Om  1.0.0
A universal framework for multimedia simulation
Public Member Functions | Protected Member Functions | List of all members
om::io::FileWriter Class Reference

A class that allows the user to easily write to a file. More...

#include <omFileWriter.h>

Inheritance diagram for om::io::FileWriter:
om::io::DataOutputStream om::io::StringOutputStream

Public Member Functions

 FileWriter (const Char *filePath)
 Create a FileWriter object that should write to the file at the specified path string. More...
 
 FileWriter (const fs::UTF8String &filePath)
 Create a FileWriter object that should write to the file at the specified path string. More...
 
 FileWriter (const fs::Path &filePath)
 Create a FileWriter object that should write to the file at the specified path. More...
 
 FileWriter (const fs::File &file)
 Create a FileWriter object that should write to the specified file. More...
 
 ~FileWriter ()
 Destroy a file reader and free all of it's resources (close the file). More...
 
const fs::FilegetFile () const
 Get the file object that this file writer is reading from. More...
 
const fs::PathgetURL () const
 Get the path to the file that this file writer is reading. More...
 
LargeSize getFileSize () const
 Get the size of the file in bytes. More...
 
Bool fileExists () const
 Get whether or not the file associated with this writer exists. More...
 
Bool open ()
 Open the file writer, allocating whatever resources needed to do so. More...
 
Bool close ()
 Close the file writer, freeing all resources used during writing. More...
 
Bool isOpen () const
 Return whether or not the file writer's file is open. More...
 
virtual Size writeData (const UByte *data, Size number)
 Write the specified number of bytes of data from the buffer to the stream. More...
 
virtual void flush ()
 Flush the file stream, sending all internally buffered output to the file. More...
 
Bool erase ()
 Erase the file associated with this file writer. More...
 
virtual Bool canSeek () const
 Return whether or not this file writer allows seeking. More...
 
virtual Bool canSeek (Int64 relativeOffset) const
 Return whether or not this stream can seek by the specified amount in bytes. More...
 
virtual Int64 seek (Int64 relativeOffset)
 Move the current position in the stream by the specified relative signed offset in bytes. More...
 
LargeIndex seekAbsolute (LargeIndex newFilePosition)
 Seek to an absolute position in the file. More...
 
Bool seekStart ()
 Rewind the file pointer to the beginning of the file. More...
 
Bool seekEnd ()
 Seek to the end of the file. More...
 
virtual LargeIndex getPosition () const
 Get the absolute position in the file of the file writer in bytes. More...
 
Bool isAtEndOfFile () const
 Get whether or not the file writer is at the end of the file. More...
 
- Public Member Functions inherited from om::io::DataOutputStream
virtual ~DataOutputStream ()
 Destroy an output stream and free all of its resources (close it). More...
 
Size writeData (const data::Data &data)
 Write as much of the specified data array to the stream and return the number of bytes written. More...
 
Size writeData (const data::DataBuffer &dataBuffer)
 Write as much of the specified data array to the stream and return the number of bytes written. More...
 
- Public Member Functions inherited from om::io::StringOutputStream
 StringOutputStream ()
 Create a StringOutputStream with the native output endianness. More...
 
 StringOutputStream (data::Endianness newEndianness)
 Create a StringOutputStream with the specified output endianness. More...
 
virtual ~StringOutputStream ()
 Destroy an output stream and free all of it's resources (close it). More...
 
Bool writeASCII (Char character)
 Write one ASCII character to the output stream. More...
 
Size writeASCII (const Char *characters)
 Write characters from the buffer until a NULl terminator is reached and return the number written. More...
 
Size writeASCII (const Char *characters, Size numCharacters)
 Write the specified number of characters from the buffer and return the number written. More...
 
Size writeASCII (const data::String &string)
 Write the specified string to the output string and return the number of characters written. More...
 
Bool writeUTF8 (UTF8Char character)
 Write one UTF-8 character to the output stream. More...
 
Size writeUTF8 (const UTF8Char *characters)
 Write characters from the buffer until a NULl terminator is reached and return the number written. More...
 
Size writeUTF8 (const UTF8Char *characters, Size numCharacters)
 Write the specified number of characters from the buffer and return the number written. More...
 
Size writeUTF8 (const data::UTF8String &string)
 Write the specified string to the output string and return the number of characters written. More...
 
Bool writeUTF16 (UTF16Char character)
 Write one UTF-16 character to the output stream. More...
 
Size writeUTF16 (const UTF16Char *characters)
 Write characters from the buffer until a NULL terminator is reached and return the number written. More...
 
Size writeUTF16 (const UTF16Char *characters, Size numCharacters)
 Write the specified number of characters from the buffer and return the number written. More...
 
Size writeUTF16 (const data::UTF16String &string)
 Write the specified string to the output string and return the number of characters written. More...
 
Bool writeUTF32 (UTF32Char character)
 Write one UTF-32 character to the output stream. More...
 
Size writeUTF32 (const UTF32Char *characters)
 Write characters from the buffer until a NULl terminator is reached and return the number written. More...
 
Size writeUTF32 (const UTF32Char *characters, Size numCharacters)
 Write the specified number of characters from the buffer and return the number written. More...
 
Size writeUTF32 (const data::UTF32String &string)
 Write the specified string to the output string and return the number of characters written. More...
 
data::Endianness getEndianness () const
 Get the current endianness of the wide characters being written to the stream. More...
 
void setEndianness (data::Endianness newEndianness)
 Set the stream to write wide characters in the specified endian format. More...
 

Protected Member Functions

virtual Size writeChars (const Char *characters, Size number)
 Write the specified number of characters from the character buffer and return the number written. More...
 
virtual Size writeUTF8Chars (const UTF8Char *characters, Size number)
 Write the specified number of UTF-8 characters from the character buffer and return the number written. More...
 
virtual Size writeUTF16Chars (const UTF16Char *characters, Size number)
 Write the specified number of UTF-16 characters from the character buffer and return the number written. More...
 
virtual Size writeUTF32Chars (const UTF32Char *characters, Size number)
 Write the specified number of UTF-32 characters from the character buffer and return the number written. More...
 

Detailed Description

A class that allows the user to easily write to a file.

This purpose of this class is to write to a file in an object oriented and flexible manner. It allows the user to write individual bytes (characters), a sequence of characters, and raw data. One can open and close the file writer, and manipulate it's position in the file by seeking an absolute position or moving relatively. This class can also create a file if it does not initially exist when the file writer is instantiated. It wraps C's standard file in/out.

Constructor & Destructor Documentation

om::io::FileWriter::FileWriter ( const Char filePath)

Create a FileWriter object that should write to the file at the specified path string.

om::io::FileWriter::FileWriter ( const fs::UTF8String &  filePath)

Create a FileWriter object that should write to the file at the specified path string.

om::io::FileWriter::FileWriter ( const fs::Path filePath)

Create a FileWriter object that should write to the file at the specified path.

om::io::FileWriter::FileWriter ( const fs::File file)

Create a FileWriter object that should write to the specified file.

om::io::FileWriter::~FileWriter ( )

Destroy a file reader and free all of it's resources (close the file).

Member Function Documentation

const fs::File& om::io::FileWriter::getFile ( ) const
inline

Get the file object that this file writer is reading from.

This method returns a constant reference to a file object representing the file that this file writer is associated with.

Returns
the file this file writer is associated with.
const fs::Path& om::io::FileWriter::getURL ( ) const
inline

Get the path to the file that this file writer is reading.

This method returns a constant reference to a string representing the path to the file that this file writer is associated with.

Returns
the path to the file this file writer is associated with.
LargeSize om::io::FileWriter::getFileSize ( ) const
inline

Get the size of the file in bytes.

This method queries and returns the size of the file in bytes. The file does not have to be open to do this, but it does have to exist. If the file does not exist, the method returns a size of 0.

Returns
the total size of the file in bytes.
Bool om::io::FileWriter::fileExists ( ) const
inline

Get whether or not the file associated with this writer exists.

This method checks whether or not the file pointed to by the path queried by getURL() exists. It then returns TRUE if the file exists or returns FALSE if the file does not exist.

Returns
whether or not the file associated with this file writer exists.
Bool om::io::FileWriter::open ( )

Open the file writer, allocating whatever resources needed to do so.

Bool om::io::FileWriter::close ( )

Close the file writer, freeing all resources used during writing.

This method closes the file writer, and ensures that all resources that it used to perform output are freed (such as files, etc.). If the file writer is currently open, then this method guarantees that the writer is closed. If the file was not able to be closed or was not already open, the method returns FALSE indicating the error. Otherwise, the method returns TRUE if it succeeds.

Bool om::io::FileWriter::isOpen ( ) const
inline

Return whether or not the file writer's file is open.

This method gets a boolean value from the file writer indicating whether or not the file is currently open. If the file is open, then TRUE is returned, and if it is closed, FALSE is returned.

Returns
whether or not the file writer is open
virtual Size om::io::FileWriter::writeData ( const UByte data,
Size  number 
)
virtual

Write the specified number of bytes of data from the buffer to the stream.

Implements om::io::DataOutputStream.

virtual void om::io::FileWriter::flush ( )
virtual

Flush the file stream, sending all internally buffered output to the file.

This method causes all currently pending output data to be sent to the file. This method ensures that this is done and that all internal data buffers are emptied if they have any contents. If this method is called when the file is not open, then a IOException is thrown indicating this mistake.

Implements om::io::DataOutputStream.

Bool om::io::FileWriter::erase ( )

Erase the file associated with this file writer.

This method erases the entire contents of the file being written and resets the current write pointer to the begining of the file. The method returns whether or not the erase operation was successful. Erasing a file can fail if the file is not open or if the file is not valid.

virtual Bool om::io::FileWriter::canSeek ( ) const
virtual

Return whether or not this file writer allows seeking.

If the file that is being written is open and valid, this method returns TRUE. Otherwise, the method returns false indicating that seeking is not allowed.

Implements om::io::DataOutputStream.

virtual Bool om::io::FileWriter::canSeek ( Int64  relativeOffset) const
virtual

Return whether or not this stream can seek by the specified amount in bytes.

Since some streams may not support rewinding, this method can be used to determine if a given seek operation can succeed. The method can also be used to determine if the end of a stream has been reached, a seek past the end of a file will fail.

Implements om::io::DataOutputStream.

virtual Int64 om::io::FileWriter::seek ( Int64  relativeOffset)
virtual

Move the current position in the stream by the specified relative signed offset in bytes.

The method attempts to seek in the stream by the specified amount and returns the signed amount that the position in the stream was changed by in bytes. A negative offset indicates that the position should be moved in reverse and a positive offset indicates that the position should be moved forwards.

Implements om::io::DataOutputStream.

LargeIndex om::io::FileWriter::seekAbsolute ( LargeIndex  newFilePosition)

Seek to an absolute position in the file.

This method attempts to seek to the specified absolute position in the file, and then returns the resulting position in the file of the file reader after the method call. Positions within a file are specified with 0 representing the beginning of the file, and each positive increment of 1 representing a position 1 more byte further in the file. If the file is not open when the method is called, no seek operation is performed and the current position in the file is returned.

Parameters
newFilePosition- The desired position in the file to seek to.
Returns
the resulting position in the file after the method call.
Bool om::io::FileWriter::seekStart ( )

Rewind the file pointer to the beginning of the file.

This method moves the position in the file of the file writer to the beginning of the file. The method returns whether or not the seek operation was successful. The seek operation can fail if seeking is not allowed or the file is not open.

Bool om::io::FileWriter::seekEnd ( )

Seek to the end of the file.

This method sets the current position in the file of the file writer to be the end of the file. The method returns whether or not the seek operation was successful. The seek operation can fail if seeking is not allowed or if the file is not open.

virtual LargeIndex om::io::FileWriter::getPosition ( ) const
virtual

Get the absolute position in the file of the file writer in bytes.

This method queries and returns the current position in the file of the file writer. Positions within a file are specified with 0 representing the beginning of the file, and each positive increment of 1 representing a position 1 more byte further in the file. If the file is not open when the method is called, then a IOException is thrown.

Returns
the current position in the file of the file writer.

Implements om::io::DataOutputStream.

Bool om::io::FileWriter::isAtEndOfFile ( ) const

Get whether or not the file writer is at the end of the file.

This method queries whether or not the file writer is at the end of the file. If it is, then TRUE is returned, otherwise FALSE is returned. If the file is not open when the method is called, then a IOException is thrown.

Returns
whether or not the file writer is at the end of the file.
virtual Size om::io::FileWriter::writeChars ( const Char characters,
Size  number 
)
protectedvirtual

Write the specified number of characters from the character buffer and return the number written.

Implements om::io::StringOutputStream.

virtual Size om::io::FileWriter::writeUTF8Chars ( const UTF8Char characters,
Size  number 
)
protectedvirtual

Write the specified number of UTF-8 characters from the character buffer and return the number written.

Implements om::io::StringOutputStream.

virtual Size om::io::FileWriter::writeUTF16Chars ( const UTF16Char characters,
Size  number 
)
protectedvirtual

Write the specified number of UTF-16 characters from the character buffer and return the number written.

Implements om::io::StringOutputStream.

virtual Size om::io::FileWriter::writeUTF32Chars ( const UTF32Char characters,
Size  number 
)
protectedvirtual

Write the specified number of UTF-32 characters from the character buffer and return the number written.

Implements om::io::StringOutputStream.


The documentation for this class was generated from the following file: