xtd 0.2.0
Loading...
Searching...
No Matches
xtd::io::stream Class Referenceabstract
Inheritance diagram for xtd::io::stream:
xtd::abstract_object xtd::object xtd::io::memory_stream xtd::net::sockets::network_stream

Definition

Provides a generic view of a sequence of bytes. This is an abstract class.

class core_export_ stream : public xtd::abstract_object, public std::iostream;
Represent an abstract class.
Definition abstract_object.hpp:27
stream()
Initializes a new instance of the xtd::io::stream class.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
Inheritance
xtd::objectabstract_objectxtd::io::text_writer
Header
#include <xtd/io/stream>
Namespace
xtd::io
Library
xtd.core

Public Fields

static xtd::io::null_stream null_stream
 A Stream with no backing store.
 
static constexpr xtd::int32 eof
 Represnets an eof value.
 

Public Properties

virtual auto can_read () const noexcept -> bool=0
 When overridden in a derived class, gets a value indicating whether the current stream supports reading.
 
virtual auto can_seek () const noexcept -> bool=0
 When overridden in a derived class, gets a value indicating whether the current stream supports seeking.
 
virtual auto can_timeout () const noexcept -> bool
 Gets a value that determines whether the current stream can time out.
 
virtual auto can_write () const noexcept -> bool=0
 Gets a value indicating whether the current stream supports writing.
 
virtual auto is_closed () const noexcept -> bool
 Indicates if the stream is closed.
 
virtual auto length () const -> xtd::size=0
 When overridden in a derived class, gets the length in bytes of the stream.
 
virtual auto position () const -> xtd::size=0
 When overridden in a derived class, gets the position within the current stream.
 
virtual auto position (xtd::size value) -> void=0
 When overridden in a derived class, sets the position within the current stream.
 
virtual auto read_timeout () const -> xtd::int32
 Gets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.
 
virtual auto read_timeout (xtd::int32 value) -> void
 Sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.
 
virtual auto write_timeout () const -> xtd::int32
 Gets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.
 
virtual auto write_timeout (xtd::int32 value) -> void
 Sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.
 

Public Methods

auto copy_to (std::ostream &destination) -> void
 Reads the bytes from the current memory stream and writes them to another stream.
 
auto copy_to (std::ostream &destination, xtd::size buffer_size) -> void
 Reads the bytes from the current memory stream and writes them to another stream, using a specified buffer size.
 
virtual auto flush () -> void=0
 When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device. exception xtd::io::io_exception An I/O error occurs.
 
virtual auto read (xtd::span< xtd::byte > &buffer) -> xtd::size
 When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
 
virtual auto read (xtd::array< xtd::byte > &buffer, xtd::size offset, xtd::size count) -> xtd::size=0
 
auto read_at_least (xtd::array< xtd::byte > &buffer, xtd::size minimum_bytes, bool throw_on_end_of_stream=true) -> xtd::size
 Reads at least a minimum number of bytes from the current stream and advances the position within the stream by the number of bytes read.
 
virtual auto read_byte () -> xtd::int32
 
auto read_exactly (xtd::array< xtd::byte > &buffer) -> void
 Reads bytes from the current stream and advances the position within the stream until the buffer is filled.
 
auto read_exactly (xtd::array< xtd::byte > &buffer, xtd::size offset, xtd::size count) -> void
 Reads count number of bytes from the current stream and advances the position within the stream.
 
virtual auto set_length (xtd::size value) -> void=0
 
virtual auto write (xtd::span< const xtd::byte > buffer) -> void
 
virtual auto write (const xtd::array< xtd::byte > &buffer, xtd::size offset, xtd::size count) -> void=0
 
virtual auto write_byte (xtd::byte value) -> void
 

Protected constructors

 stream ()
 Initializes a new instance of the xtd::io::stream class.
 

Additional Inherited Members

 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.
 
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.
 
 abstract_object ()=default
 Initializes a new instance of the xtd::abstract_object class.
 

Constructor & Destructor Documentation

◆ stream()

xtd::io::stream::stream ( )
protected

Initializes a new instance of the xtd::io::stream class.

Remarks
xtd::io::stream is the abstract base class of all streams.
Some of the more commonly used streams that inherit from xtd:io::stream are xtd:io::file_stream, and xtd:io::memory_stream.
This constructor exposes the underlying stream, which xtd::io::stream::get_buffer returns.

Member Function Documentation

◆ can_read()

virtual auto xtd::io::stream::can_read ( ) const -> bool
nodiscardpure virtualnoexcept

When overridden in a derived class, gets a value indicating whether the current stream supports reading.

Returns
true if the stream supports reading; otherwise, false.

Implemented in xtd::io::memory_stream, and xtd::net::sockets::network_stream.

◆ can_seek()

virtual auto xtd::io::stream::can_seek ( ) const -> bool
nodiscardpure virtualnoexcept

When overridden in a derived class, gets a value indicating whether the current stream supports seeking.

Returns
true if the stream supports seeking; otherwise, false.

Implemented in xtd::io::memory_stream, and xtd::net::sockets::network_stream.

◆ can_timeout()

virtual auto xtd::io::stream::can_timeout ( ) const -> bool
nodiscardvirtualnoexcept

Gets a value that determines whether the current stream can time out.

Returns
A value that determines whether the current stream can time out.
Remarks
The xtd::io::stream::can_timeout property always returns false. Some stream implementations require different behavior, such as xtd::net::sockets::network_stream, which times out if network connectivity is interrupted or lost. If you are implementing a stream that must be able to time out, this property should be overridden to return true.

Reimplemented in xtd::net::sockets::network_stream.

◆ can_write()

virtual auto xtd::io::stream::can_write ( ) const -> bool
nodiscardpure virtualnoexcept

Gets a value indicating whether the current stream supports writing.

Returns
true if the stream supports writing; otherwise, false.

Implemented in xtd::io::memory_stream, and xtd::net::sockets::network_stream.

◆ is_closed()

virtual auto xtd::io::stream::is_closed ( ) const -> bool
nodiscardvirtualnoexcept

Indicates if the stream is closed.

Returns
true if the stream is closed, false otherwise

◆ length()

virtual auto xtd::io::stream::length ( ) const -> xtd::size
nodiscardpure virtual

When overridden in a derived class, gets the length in bytes of the stream.

Returns
The length of the stream in bytes.
Exceptions
xtd::not_supported_exceptionA class derived from xtd::io::stream does not support seeking and the length is unknown.

Implemented in xtd::io::memory_stream, and xtd::net::sockets::network_stream.

◆ position() [1/2]

virtual auto xtd::io::stream::position ( ) const -> xtd::size
nodiscardpure virtual

When overridden in a derived class, gets the position within the current stream.

Returns
The current position within the stream.
Exceptions
xtd::not_supported_exceptionThe stream does not support seeking.
Remarks
The stream must support seeking to get or set the position. Use the xtd::io::stream::can_seek property to determine whether the stream supports seeking.
Seeking to any location beyond the length of the stream is supported.

Implemented in xtd::io::memory_stream, and xtd::net::sockets::network_stream.

◆ position() [2/2]

virtual auto xtd::io::stream::position ( xtd::size value) -> void
pure virtual

When overridden in a derived class, sets the position within the current stream.

Parameters
valueThe current position within the stream.
Exceptions
xtd::not_supported_exceptionThe stream does not support seeking.
Remarks
The stream must support seeking to get or set the position. Use the xtd::io::stream::can_seek property to determine whether the stream supports seeking.
Seeking to any location beyond the length of the stream is supported.

Implemented in xtd::io::memory_stream, and xtd::net::sockets::network_stream.

◆ read_timeout() [1/2]

virtual auto xtd::io::stream::read_timeout ( ) const -> xtd::int32
nodiscardvirtual

Gets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.

Returns
A value, in milliseconds, that determines how long the stream will attempt to read before timing out.
Exceptions
xtd::invalid_operation_exceptionThe xtd::io::stream::read_timeout method always throws an xtd::invalid_operation_exception.
Notes to Inheritors
The xtd::io::stream::read_timeout property should be overridden to provide the appropriate behavior for the stream. If the stream does not support timing out, this property should raise an xtd::invalid_operation_exception.

Reimplemented in xtd::net::sockets::network_stream.

◆ read_timeout() [2/2]

virtual auto xtd::io::stream::read_timeout ( xtd::int32 value) -> void
virtual

Sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.

Parameters
valueA value, in milliseconds, that determines how long the stream will attempt to read before timing out.
Exceptions
xtd::invalid_operation_exceptionThe xtd::io::stream::read_timeout method always throws an xtd::invalid_operation_exception.
Notes to Inheritors
The xtd::io::stream::read_timeout property should be overridden to provide the appropriate behavior for the stream. If the stream does not support timing out, this property should raise an xtd::invalid_operation_exception.

Reimplemented in xtd::net::sockets::network_stream.

◆ write_timeout() [1/2]

virtual auto xtd::io::stream::write_timeout ( ) const -> xtd::int32
nodiscardvirtual

Gets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.

Returns
A value, in milliseconds, that determines how long the stream will attempt to write before timing out.
Exceptions
xtd::invalid_operation_exceptionThe xtd::io::stream::write_timeout method always throws an xtd::invalid_operation_exception.
Notes to Inheritors
The xtd::io::stream::write_timeout property should be overridden to provide the appropriate behavior for the stream. If the stream does not support timing out, this property should raise an xtd::invalid_operation_exception.

Reimplemented in xtd::net::sockets::network_stream.

◆ write_timeout() [2/2]

virtual auto xtd::io::stream::write_timeout ( xtd::int32 value) -> void
virtual

Sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.

Parameters
valueA value, in milliseconds, that determines how long the stream will attempt to write before timing out.
Exceptions
xtd::invalid_operation_exceptionThe xtd::io::stream::write_timeout method always throws an xtd::invalid_operation_exception.
Notes to Inheritors
The xtd::io::stream::write_timeout property should be overridden to provide the appropriate behavior for the stream. If the stream does not support timing out, this property should raise an xtd::invalid_operation_exception.

Reimplemented in xtd::net::sockets::network_stream.

◆ copy_to() [1/2]

auto xtd::io::stream::copy_to ( std::ostream & destination) -> void

Reads the bytes from the current memory stream and writes them to another stream.

Parameters
destinationThe stream to which the contents of the current memory stream will be copied.

◆ copy_to() [2/2]

auto xtd::io::stream::copy_to ( std::ostream & destination,
xtd::size buffer_size ) -> void

Reads the bytes from the current memory stream and writes them to another stream, using a specified buffer size.

Parameters
destinationThe stream to which the contents of the current memory stream will be copied.
buffer_sizeThe size of the buffer. This value must be greater than zero. The default size is 81920.

◆ flush()

virtual auto xtd::io::stream::flush ( ) -> void
pure virtual

When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device. exception xtd::io::io_exception An I/O error occurs.

Implemented in xtd::io::memory_stream, and xtd::net::sockets::network_stream.

◆ read() [1/2]

virtual auto xtd::io::stream::read ( xtd::span< xtd::byte > & buffer) -> xtd::size
virtual

When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

Parameters
bufferA region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current source.

Reimplemented in xtd::io::memory_stream, and xtd::net::sockets::network_stream.

◆ read() [2/2]

virtual auto xtd::io::stream::read ( xtd::array< xtd::byte > & buffer,
xtd::size offset,
xtd::size count ) -> xtd::size
pure virtual

◆ read_at_least()

auto xtd::io::stream::read_at_least ( xtd::array< xtd::byte > & buffer,
xtd::size minimum_bytes,
bool throw_on_end_of_stream = true ) -> xtd::size

Reads at least a minimum number of bytes from the current stream and advances the position within the stream by the number of bytes read.

Parameters
bufferA region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current stream.
minimum_bytesThe minimum number of bytes to read into the buffer.
throw_on_end_of_streamtrue to throw an exception if the end of the stream is reached before reading minimumBytes of bytes; false to return less than minimum_bytes when the end of the stream is reached. The default is true.
Returns
The total number of bytes read into the buffer. This is guaranteed to be greater than or equal to minimum_bytes when throw_on_end_of_stream is true. This will be less than minimum_bytes when the end of the stream is reached and throw_on_end_of_stream is false. This can be less than the number of bytes allocated in the buffer if that many bytes are not currently available.
Exceptions
xtd::argument_out_of_range_exception`minimum_bytes` is greater than the length of `buffer`.
xtd::io::end_of_stream_exception`throw_on_end_of_stream` is `true` and the end of the stream is reached before reading `minimum_bytes` bytes of data.
Remarks
When minimum_bytes is 0 (zero), this read operation will be completed without waiting for available data in the stream.

◆ read_exactly() [1/2]

auto xtd::io::stream::read_exactly ( xtd::array< xtd::byte > & buffer) -> void

Reads bytes from the current stream and advances the position within the stream until the buffer is filled.

Parameters
bufferA region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current stream
Exceptions
xtd::end_of_stream_exceptionThe end of the stream is reached before filling the buffer.
Remarks
When buffer is empty, this read operation will be completed without waiting for available data in the stream.

◆ read_exactly() [2/2]

auto xtd::io::stream::read_exactly ( xtd::array< xtd::byte > & buffer,
xtd::size offset,
xtd::size count ) -> void

Reads count number of bytes from the current stream and advances the position within the stream.

Parameters
bufferAn array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current stream.
offsetThe byte offset in buffer at which to begin storing the data read from the current stream.
countThe number of bytes to be read from the current stream.
Exceptions
xtd::argument_out_of_range_exceptionoffset is outside the bounds of buffer.
-or-
The range specified by the combination of offset and count exceeds the length of buffer.
xtd::io::end_of_stream_exception`throw_on_end_of_stream` is `true` and the end of the stream is reached before reading `minimum_bytes` bytes of data.
Remarks
When count is 0 (zero), this read operation will be completed without waiting for available data in the stream.

◆ set_length()

virtual auto xtd::io::stream::set_length ( xtd::size value) -> void
pure virtual

◆ write()

virtual auto xtd::io::stream::write ( const xtd::array< xtd::byte > & buffer,
xtd::size offset,
xtd::size count ) -> void
pure virtual

Member Data Documentation

◆ null_stream

xtd::io::null_stream xtd::io::stream::null_stream
static

A Stream with no backing store.

Remarks
Use xtd::io::stream::null_stream to redirect output to a stream that will not consume any operating system resources. When the methods of xtd::io::stream that provide writing are invoked on xtd::io::stream::null_stream, the call simply returns, and no data is written. xtd::io::stream::null_stream also implements a xtd::io::stream::stream::read method that returns zero without reading data.

◆ eof

xtd::int32 xtd::io::stream::eof
inlinestaticconstexpr

Represnets an eof value.

Remarks
Returns a value not equivalent to any valid value of stream type (EOF (-1)).

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