Minecraft Community Edition 0.1.0
Loading...
Searching...
No Matches
mce::FileOutputStream Class Referencefinal

Platform-independent file output stream implementation. More...

#include <FileOutputStream.hpp>

Inheritance diagram for mce::FileOutputStream:
mce::OutputStream

Public Member Functions

 FileOutputStream ()=default
 Default constructor.
bool open (const std::string &file)
 Opens a file for writing (creates/truncates by default).
bool isOpen () const
 Query whether the underlying file handle is open.
void close ()
 Close the file and release any resources.
size_t write (const void *buffer, size_t size) override
 Write bytes to the file.
size_t seek (size_t position) override
 Change the current write position in the file.
size_t tell () override
 Get the current write position in the file.
size_t getSize () override
 Get the total size of the underlying file in bytes.

Static Public Attributes

static constexpr size_t INVALID_FILE_SIZE = ~(0)
 Constant indicating an invalid file size/position.
static constexpr size_t INVALID_FILE_POSITION = ~(0)
 Constant indicating an invalid file position.

Detailed Description

Platform-independent file output stream implementation.

Provides a concrete OutputStream that writes data to a file using the platform native file handle or FILE* depending on the platform.

Member Function Documentation

◆ getSize()

size_t mce::FileOutputStream::getSize ( )
overridevirtual

Get the total size of the underlying file in bytes.

Returns
File size in bytes or INVALID_FILE_SIZE on error.

Implements mce::OutputStream.

◆ isOpen()

bool mce::FileOutputStream::isOpen ( ) const

Query whether the underlying file handle is open.

Returns
True when the file is open and ready for writing.

◆ open()

bool mce::FileOutputStream::open ( const std::string & file)

Opens a file for writing (creates/truncates by default).

Parameters
filePath (absolute or relative) to the file to open.
Returns
True if the file was successfully opened.

◆ seek()

size_t mce::FileOutputStream::seek ( size_t position)
overridevirtual

Change the current write position in the file.

Parameters
positionThe absolute position (in bytes) to seek to.
Returns
The new position in the file after seeking.

Implements mce::OutputStream.

◆ tell()

size_t mce::FileOutputStream::tell ( )
overridevirtual

Get the current write position in the file.

Returns
Current position in bytes from the start of the file.

Implements mce::OutputStream.

◆ write()

size_t mce::FileOutputStream::write ( const void * buffer,
size_t size )
overridevirtual

Write bytes to the file.

Parameters
bufferPointer to the data to write.
sizeNumber of bytes to write from buffer.
Returns
Number of bytes actually written.

Implements mce::OutputStream.

Member Data Documentation

◆ INVALID_FILE_SIZE

size_t mce::FileOutputStream::INVALID_FILE_SIZE = ~(0)
inlinestaticconstexpr

Constant indicating an invalid file size/position.

This value is returned by getSize() or tell() when the operation fails.


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