Creates a stream whose backing store is memory.
Public constructors | |
memory_stream () | |
Initializes a new instance of the MemoryStream class with an expandable capacity initialized to zero. | |
memory_stream (xtd::size capacity) | |
Initializes a new instance of the MemoryStream class with an expandable capacity initialized as specified. | |
Public Properties | |
bool | can_read () const noexcept override |
Gets a value indicating whether the current stream supports reading. | |
bool | can_seek () const noexcept override |
Gets a value indicating whether the current stream supports seeking. | |
bool | can_write () const noexcept override |
Gets a value indicating whether the current stream supports writing. | |
xtd::size | capacity () const |
Gets the number of bytes allocated for this stream. | |
void | capacity (xtd::size value) |
Sets the number of bytes allocated for this stream. | |
xtd::size | length () const override |
Gets the length of the stream in bytes. | |
xtd::size | position () const override |
Gets the current position within the stream. | |
void | position (xtd::size value) override |
Sets the current position within the stream. | |
Public Methods | |
void | flush () override |
Overrides the Flush() method so that no action is performed. | |
xtd::size | read (xtd::array< xtd::byte > &buffer, size offset, size count) override |
Reads a block of bytes from the current stream and writes the data to a buffer. | |
xtd::size | seek (std::streamoff offset, seek_origin loc) |
Sets the position within the current stream to the specified value. | |
void | set_length (xtd::size value) override |
Sets the length of the current stream to the specified value. | |
xtd::array< xtd::byte > | to_array () const |
Writes the stream contents to a byte array, regardless of the Position property. | |
void | write (const xtd::array< xtd::byte > &buffer, size offset, size count) override |
Writes a block of bytes to the current stream using data read from a buffer. | |
void | write_to (std::ostream &stream) |
Writes the entire contents of this memory stream to another stream. | |
Additional Inherited Members | |
![]() | |
static xtd::io::null_stream | null_stream |
A Stream with no backing store. | |
static constexpr int32 | eof |
Represnets an eof value. | |
![]() | |
virtual bool | can_timeout () const noexcept |
Gets a value that determines whether the current stream can time out. | |
virtual bool | is_closed () const noexcept |
Indicates if the stream is closed. | |
virtual int32 | read_timeout () const |
Gets a value, in milliseconds, that determines how long the stream will attempt to read before timing out. | |
virtual void | read_timeout (int32 value) |
Sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out. | |
virtual int32 | write_timeout () const |
Gets a value, in milliseconds, that determines how long the stream will attempt to write before timing out. | |
virtual void | write_timeout (int32 value) |
Sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out. | |
void | copy_to (std::ostream &destination) |
Reads the bytes from the current memory stream and writes them to another stream. | |
void | copy_to (std::ostream &destination, xtd::size buffer_size) |
Reads the bytes from the current memory stream and writes them to another stream, using a specified buffer size. | |
virtual xtd::size | read (xtd::span< xtd::byte > &buffer) |
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. | |
xtd::size | read_at_least (xtd::array< xtd::byte > &buffer, xtd::size minimum_bytes, bool throw_on_end_of_stream=true) |
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 int32 | read_byte () |
void | read_exactly (xtd::array< xtd::byte > &buffer) |
Reads bytes from the current stream and advances the position within the stream until the buffer is filled. | |
void | read_exactly (xtd::array< xtd::byte > &buffer, xtd::size offset, xtd::size count) |
Reads count number of bytes from the current stream and advances the position within the stream. | |
virtual void | write (xtd::span< const xtd::byte > buffer) |
virtual void | write_byte (xtd::byte value) |
![]() | |
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::uptr< object_t > | memberwise_clone () const |
Creates a shallow copy of the current object. | |
virtual xtd::string | to_string () const noexcept |
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. | |
![]() | |
stream () | |
Initializes a new instance of the xtd::io::stream class. | |
![]() | |
abstract_object ()=default | |
Initializes a new instance of the xtd::abstract_object class. | |
xtd::io::memory_stream::memory_stream | ( | ) |
Initializes a new instance of the MemoryStream class with an expandable capacity initialized to zero.
true
. xtd::io::memory_stream::memory_stream | ( | xtd::size | capacity | ) |
Initializes a new instance of the MemoryStream class with an expandable capacity initialized as specified.
capacity | The initial size of the internal array in bytes. |
true
.
|
overridevirtualnoexcept |
Gets a value indicating whether the current stream supports reading.
true
if the stream supports reading; otherwise, false
. Implements xtd::io::stream.
|
overridevirtualnoexcept |
Gets a value indicating whether the current stream supports seeking.
true
if the stream supports seeking; otherwise, false
. Implements xtd::io::stream.
|
overridevirtualnoexcept |
Gets a value indicating whether the current stream supports writing.
true
if the stream supports writing; otherwise, false
. Implements xtd::io::stream.
xtd::size xtd::io::memory_stream::capacity | ( | ) | const |
Gets the number of bytes allocated for this stream.
xtd::argument_out_of_range_exception | A capacity is less than the current length of the stream. |
capacity
is the buffer length for system-provided byte arrays. capacity
cannot be set to a value less than the current length of the stream. void xtd::io::memory_stream::capacity | ( | xtd::size | value | ) |
Sets the number of bytes allocated for this stream.
value | The length of the usable portion of the buffer for the stream. |
xtd::argument_out_of_range_exception | A capacity is less than the current length of the stream. |
capacity
is the buffer length for system-provided byte arrays. capacity
cannot be set to a value less than the current length of the stream.
|
overridevirtual |
Gets the length of the stream in bytes.
Implements xtd::io::stream.
|
overridevirtual |
Gets the current position within the stream.
Implements xtd::io::stream.
|
overridevirtual |
Sets the current position within the stream.
value | The current position within the stream. |
Implements xtd::io::stream.
|
overridevirtual |
Overrides the Flush() method so that no action is performed.
Implements xtd::io::stream.
|
overridevirtual |
Reads a block of bytes from the current stream and writes the data to a buffer.
buffer | When this method returns, contains the specified byte array with the values between offset and (offset + count - 1) replaced by the characters read from the current stream. |
offset | The zero-based byte offset in buffer at which to begin storing data from the current stream. |
count | The maximum number of bytes to read. |
offset
parameter gives the offset of the first byte in buffer
to which data from the current stream is written. The count
parameter gives the maximum number of bytes to read from the current stream. The returned value is the actual number of bytes read, or zero if the end of the stream is reached. read
method will return zero only if the end of the stream is reached. In all other cases, read
always reads at least one byte from the stream before returning. By definition, if no data is available from the stream upon a call to read
, the read
method returns zero (the end of the stream is reached automatically). An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached. Implements xtd::io::stream.
xtd::size xtd::io::memory_stream::seek | ( | std::streamoff | offset, |
seek_origin | loc | ||
) |
Sets the position within the current stream to the specified value.
offset | The new position within the stream. This is relative to the loc parameter, and can be positive or negative. |
loc | A value of type xtd::io::seek_origin, which acts as the seek reference point. |
|
overridevirtual |
Sets the length of the current stream to the specified value.
value | The value at which to set the length. |
Implements xtd::io::stream.
xtd::array< xtd::byte > xtd::io::memory_stream::to_array | ( | ) | const |
Writes the stream contents to a byte array, regardless of the Position property.
|
overridevirtual |
Writes a block of bytes to the current stream using data read from a buffer.
buffer | The buffer to write data from. |
offset | The zero-based byte offset in buffer at which to begin copying bytes to the current stream. |
count | The maximum number of bytes to write. |
offset
parameter gives the offset of the first byte in buffer
to write from, and the count
parameter gives the number of bytes to write. If the write operation is successful, the current position within the stream is advanced by the number of bytes written. If an exception occurs, the current position within the stream is unchanged. memory_stream
constructed with a byte[] parameter, write operations at the end of a memory_stream
expand the memory_stream
. Implements xtd::io::stream.
void xtd::io::memory_stream::write_to | ( | std::ostream & | stream | ) |
Writes the entire contents of this memory stream to another stream.
stream | The stream to write this memory stream to. |
xtd::bject_closed_exception | The current or target stream is closed. |