nn::fs::FileOutputStream Class

Syntax

class FileOutputStream : 
    private nn::fs::IOutputStream,
    private nn::fs::detail::FileBase,
    private nn::util::NonCopyable< FileOutputStream >

Description

Class for writing to files.

Open a file specified by a path name and write data to it.

To improve the efficiency of writing to files, if the TryWrite or Write functions are called with flush = false, physical storage itself will not actually be written. Instead, write data will temporarily be saved in a buffer managed by the system. To actually write to physical storage (flush the buffer), call these write functions with flush = true. Then, either indicate that the buffer should be flushed after data is written or explicitly flush it by calling TryFlush. If a file is closed by executing the Finalize function or a destructor, without flushing this buffer, programs will stop if using other than Release version libraries. Plans call for changing this in the next SDK, so that programs will stop even in the case of Release versions.

If writing the same file consecutively more than once, after writing is finished using flush = false for efficiency, be sure to finally call TryFlush.

You can specify path names using both wide strings and multibyte strings. If you specify a multibyte string, a buffer for conversion to wide characters will be allocated on the stack. Be careful with conversions to wide characters, though, because they are not thread-safe. You should use a wide string unless you have a specific reason not to.

This class cannot be used to create new files in expanded save data. For that, use a TryCreateFile function that specifies the size.

Limitations

When writing to a file, performance will degrade enormously if the write position and buffer alignment do not match.
We recommend writing to files in multiples of four bytes and also aligning your buffer on a multiple of four bytes.

Member Functions

FileOutputStream Constructor.
Initialize Opens the specified file.
TryInitialize Opens the specified file.
Finalize Closes a file.
V ~FileOutputStream Destructor.
V Write Writes the specified amount of data from a buffer to a file.
V TryWrite Writes the specified amount of data from a buffer to a file.
V Seek Changes the access position in the file.
V TrySeek Changes the access position in the file.
V GetPosition Gets the current write position relative to the start of the file.
V TryGetPosition Gets the current write position relative to the start of the file.
V SetPosition Sets the current write position relative to the start of the file.
V TrySetPosition Sets the current write position relative to the start of the file.
V GetSize Gets the file size.
V TryGetSize Gets the file size.
V SetSize Sets the file size.
V TrySetSize Sets the file size.
V Flush Writes the file cache back to the device.
V TryFlush Writes the file cache back to the device.
SetPriority Sets a stream's access priority.
TrySetPriority Sets a stream's access priority.

Class Hierarchy

nn::fs::IPositionable
  nn::fs::IOutputStream
    nn::fs::FileOutputStream

Revision History

2012/01/23
Added description of flushing the buffer.
2011/11/08
Noted that conversions to wide strings are not thread-safe.
2011/10/12
Added functions for setting access priorities.
2011/03/14
Added note about limitation of write position and buffer alignment.
2010/01/29
Initial version.

CONFIDENTIAL