xtd 0.2.0
Loading...
Searching...
No Matches
xtd::io::stream_writer Class Reference
Inheritance diagram for xtd::io::stream_writer:
xtd::io::text_writer xtd::object

Definition

Implements a xtd::io::text_writer for writing characters to a stream.

stream_writer(const xtd::string &path)
Initializes a new instance of the stream_writer class for the specified file name.
Represents a writer that can write a sequential series of characters.
Definition text_writer.hpp:36
#define core_export_
Define shared library export.
Definition core_export.hpp:13
Inheritance
xtd::io::text_writerxtd::io::stream_writer
Header
#include <xtd/io/stream_writer>
Namespace
xtd::io
Library
xtd.core

Public Constructors

 stream_writer (const xtd::string &path)
 Initializes a new instance of the stream_writer class for the specified file name.
 
 stream_writer (std::ostream &stream)
 Initializes a new instance of the stream_writer class for the specified stream.
 
 stream_writer (const xtd::string &path, bool append)
 Initializes a new instance of the xtd::io::stream_writer class for the specified file on the specified path, using the default encoding and buffer size. If the file exists, it can be either overwritten or appended to. If the file does not exist, this constructor creates a new file.
 
 stream_writer (std::ostream &stream, bool append)
 Initializes a new instance of the stream_writer class for the specified stream.
 

Public Properties

auto auto_flush () const -> bool
 Gets a value indicating whether the xtd::io::stream_writer will flush its buffer to the underlying stream after every call to xtd::io::text_writer::write(char).
 
auto auto_flush (bool auto_flush) -> void
 Sets a value indicating whether the xtd::io::stream_writer will flush its buffer to the underlying stream after every call to xtd::io::text_writer::write(char).
 
auto base_stream () const -> std::optional< xtd::ref< std::ostream > >
 Returns the underlying stream.
 

Public Methods

auto close () -> void override
 Closes the stream_writer object and the underlying stream, and releases any system resources associated with the reader.
 
auto flush () -> void override
 Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
 
auto write (const xtd::string &value) -> void override
 Writes the specified string value to the text stream.
 
auto write (bool value) -> void
 Writes the specified bool value to the text stream.
 
auto write (double value) -> void
 Writes the specified double value to the text stream.
 
auto write (float value) -> void
 Writes the specified float value to the text stream.
 
auto write (sbyte value) -> void
 Writes the specified sbyte value to the text stream.
 
auto write (int16 value) -> void
 Writes the specified int16 value to the text stream.
 
auto write (int32 value) -> void
 Writes the specified int32 value to the text stream.
 
auto write (int64 value) -> void
 Writes the specified int64 value to the text stream.
 
auto write (xtd::byte value) -> void
 Writes the specified xtd::byte value to the text stream.
 
auto write (uint16 value) -> void
 Writes the specified uint16 value to the text stream.
 
auto write (uint32 value) -> void
 Writes the specified uint32 value to the text stream.
 
auto write (uint64 value) -> void
 Writes the specified uint64 value to the text stream.
 
template<class value_t>
auto write (value_t value) -> void
 Writes the specified value_t value to the text stream.
 
template<class ... args_t>
auto write (const xtd::string &fmt, args_t &&... args) noexcept -> void
 Writes the specified arguments with specified format to the text stream.
 

Additional Inherited Members

auto new_line () const noexcept -> const xtd::string &
 Gets the line terminator string used by the current text_writer.
 
auto new_line (const xtd::string &new_line) noexcept -> void
 Sets the line terminator string used by the current text_writer.
 
auto write (bool value) -> void
 Writes the specified bool value to the text stream.
 
auto write (double value) -> void
 Writes the specified double value to the text stream.
 
auto write (float value) -> void
 Writes the specified float value to the text stream.
 
auto write (sbyte value) -> void
 Writes the specified sbyte value to the text stream.
 
auto write (int16 value) -> void
 Writes the specified int16 value to the text stream.
 
auto write (int32 value) -> void
 Writes the specified int32 value to the text stream.
 
auto write (int64 value) -> void
 Writes the specified int64 value to the text stream.
 
auto write (xtd::byte value) -> void
 Writes the specified xtd::byte value to the text stream.
 
auto write (uint16 value) -> void
 Writes the specified uint16 value to the text stream.
 
auto write (uint32 value) -> void
 Writes the specified uint32 value to the text stream.
 
auto write (uint64 value) -> void
 Writes the specified uint64 value to the text stream.
 
template<class value_t>
auto write (value_t value) -> void
 Writes the specified value_t value to the text stream.
 
template<class ... args_t>
auto write (const xtd::string &fmt, args_t &&... args) noexcept -> void
 Writes the specified arguments with specified format to the text stream.
 
auto write_line () -> void
 Writes new line to the text stream.
 
auto write_line (const xtd::string &value) -> void
 Writes the specified string value and new line to the text stream.
 
auto write_line (bool value) -> void
 Writes the specified bool value and new line to the text stream.
 
auto write_line (double value) -> void
 Writes the specified double value and new line to the text stream.
 
auto write_line (float value) -> void
 Writes the specified float value and new line to the text stream.
 
auto write_line (sbyte value) -> void
 Writes the specified sbyte value and new line to the text stream.
 
auto write_line (int16 value) -> void
 Writes the specified int16 value and new line to the text stream.
 
auto write_line (int32 value) -> void
 Writes the specified int32 value and new line to the text stream.
 
auto write_line (int64 value) -> void
 Writes the specified int64 value and new line to the text stream.
 
auto write_line (xtd::byte value) -> void
 Writes the specified xtd::byte value and new line to the text stream.
 
auto write_line (uint16 value) -> void
 Writes the specified uint16 value and new line to the text stream.
 
auto write_line (uint32 value) -> void
 Writes the specified uint32 value and new line to the text stream.
 
auto write_line (uint64 value) -> void
 Writes the specified uint64 value and new line to the text stream.
 
template<class value_t>
auto write_line (value_t value) -> void
 Writes the specified value_t value and new line to the text stream.
 
template<class ... args_t>
auto write_line (const xtd::string &fmt, args_t &&... args) noexcept -> void
 Writes the specified arguments with specified format to the text stream.
 
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual xtd::size get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<class object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual xtd::string to_string () const
 Returns a xtd::string that represents the current object.
 
static auto null () noexcept -> null_text_writer &
 Provides a text_writer with no backing store that can be written to, but not read from.
 
static auto synchronised (text_writer &writer) noexcept -> synchronized_text_writer
 Creates a thread-safe (synchronized) wrapper around the specified text_writer object.
 
template<class object_a_t, class object_b_t>
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<class object_a_t, class object_b_t>
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 
 text_writer ()=default
 Initializes a new instance of the xtd::io::text_writer class.
 

Constructor & Destructor Documentation

◆ stream_writer() [1/4]

xtd::io::stream_writer::stream_writer ( const xtd::string & path)
explicit

Initializes a new instance of the stream_writer class for the specified file name.

Parameters
pathThe complete file path to be read.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened

◆ stream_writer() [2/4]

xtd::io::stream_writer::stream_writer ( std::ostream & stream)
explicit

Initializes a new instance of the stream_writer class for the specified stream.

Parameters
streamThe stream to be read.

◆ stream_writer() [3/4]

xtd::io::stream_writer::stream_writer ( const xtd::string & path,
bool append )

Initializes a new instance of the xtd::io::stream_writer class for the specified file on the specified path, using the default encoding and buffer size. If the file exists, it can be either overwritten or appended to. If the file does not exist, this constructor creates a new file.

Parameters
pathThe complete file path to write to.
appendDetermines whether data is to be appended to the file. If the file exists and append is false, the file is overwritten. If the file exists and append is true the data is appended to the file. Otherwise, a new file is created.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened

◆ stream_writer() [4/4]

xtd::io::stream_writer::stream_writer ( std::ostream & stream,
bool append )

Initializes a new instance of the stream_writer class for the specified stream.

Parameters
streamThe stream to be read.

Member Function Documentation

◆ auto_flush() [1/2]

auto xtd::io::stream_writer::auto_flush ( ) const -> bool
nodiscard

Gets a value indicating whether the xtd::io::stream_writer will flush its buffer to the underlying stream after every call to xtd::io::text_writer::write(char).

Returns
true to force xtd::io::stream_writer to flush its buffer; otherwise, false.
Remarks
Flushing the stream will not flush its underlying encoder unless you explicitly call xtd::io::stream_writer::flush or xtd::io::stream_writer::close. Setting xtd::io::stream_writer::auto_flush to true means that data will be flushed from the buffer to the stream after each write operation, but the encoder state will not be flushed.
When xtd::io::stream_writer::auto_flush is set to false, xtd::io::stream_writer will do a limited amount of buffering, both internally and potentially in the encoder from the encoding you passed in. You can get better performance by setting AutoFlush to false, assuming that you always call xtd::io::stream_writer::close (or at least Flush) when you're done writing with a xtd::io::stream_writer.
For example, set xtd::io::stream_writer::auto_flush to true when you are writing to a device where the user expects immediate feedback. xtd::console::out is one of these cases: The xtd::io::stream_writer used internally for writing to xtd::console flushes all its internal state except the encoder state after every call to xtd::io::stream_writer::write.
For a list of common I/O tasks, see Common I/O Tasks.

◆ auto_flush() [2/2]

auto xtd::io::stream_writer::auto_flush ( bool auto_flush) -> void

Sets a value indicating whether the xtd::io::stream_writer will flush its buffer to the underlying stream after every call to xtd::io::text_writer::write(char).

Parameters
auto_flushtrue to force xtd::io::stream_writer to flush its buffer; otherwise, false.
Remarks
Flushing the stream will not flush its underlying encoder unless you explicitly call xtd::io::stream_writer::flush or xtd::io::stream_writer::close. Setting xtd::io::stream_writer::auto_flush to true means that data will be flushed from the buffer to the stream after each write operation, but the encoder state will not be flushed.
When xtd::io::stream_writer::auto_flush is set to false, xtd::io::stream_writer will do a limited amount of buffering, both internally and potentially in the encoder from the encoding you passed in. You can get better performance by setting AutoFlush to false, assuming that you always call xtd::io::stream_writer::close (or at least Flush) when you're done writing with a xtd::io::stream_writer.
For example, set xtd::io::stream_writer::auto_flush to true when you are writing to a device where the user expects immediate feedback. xtd::console::out is one of these cases: The xtd::io::stream_writer used internally for writing to xtd::console flushes all its internal state except the encoder state after every call to xtd::io::stream_writer::write.
For a list of common I/O tasks, see Common I/O Tasks.

◆ base_stream()

auto xtd::io::stream_writer::base_stream ( ) const -> std::optional< xtd::ref< std::ostream > >
nodiscard

Returns the underlying stream.

Returns
The underlying stream.

◆ close()

auto xtd::io::stream_writer::close ( ) -> void
overridevirtual

Closes the stream_writer object and the underlying stream, and releases any system resources associated with the reader.

Reimplemented from xtd::io::text_writer.

◆ flush()

auto xtd::io::stream_writer::flush ( ) -> void
overridevirtual

Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.

Remarks
This default method does nothing, but derived classes can virtual the method to provide the appropriate functionality

Reimplemented from xtd::io::text_writer.

◆ write() [1/14]

auto xtd::io::stream_writer::write ( const xtd::string & value) -> void
overridevirtual

Writes the specified string value to the text stream.

Parameters
valueThe value to write
Exceptions
io::io_exceptionAn I/O error occurs.

Reimplemented from xtd::io::text_writer.

◆ write() [2/14]

auto xtd::io::text_writer::write ( bool value) -> void

Writes the specified bool value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [3/14]

auto xtd::io::text_writer::write ( double value) -> void

Writes the specified double value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [4/14]

auto xtd::io::text_writer::write ( float value) -> void

Writes the specified float value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [5/14]

auto xtd::io::text_writer::write ( sbyte value) -> void

Writes the specified sbyte value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [6/14]

auto xtd::io::text_writer::write ( int16 value) -> void

Writes the specified int16 value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [7/14]

auto xtd::io::text_writer::write ( int32 value) -> void

Writes the specified int32 value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [8/14]

auto xtd::io::text_writer::write ( int64 value) -> void

Writes the specified int64 value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [9/14]

auto xtd::io::text_writer::write ( xtd::byte value) -> void

Writes the specified xtd::byte value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [10/14]

auto xtd::io::text_writer::write ( uint16 value) -> void

Writes the specified uint16 value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [11/14]

auto xtd::io::text_writer::write ( uint32 value) -> void

Writes the specified uint32 value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [12/14]

auto xtd::io::text_writer::write ( uint64 value) -> void

Writes the specified uint64 value to the text stream.

Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [13/14]

template<class value_t>
auto xtd::io::text_writer::write ( value_t value) -> void
inline

Writes the specified value_t value to the text stream.

Template Parameters
value_tThe type of value to write.
Parameters
valueThe value to write.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ write() [14/14]

template<class ... args_t>
auto xtd::io::text_writer::write ( const xtd::string & fmt,
args_t &&... args ) -> void
inlinenoexcept

Writes the specified arguments with specified format to the text stream.

Parameters
formatThe arguments format to write.
argsThe arguments to write with format
Exceptions
io::io_exceptionAn I/O error occurs.

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