An implementation of the ITextStream that uses a growing memory buffer.
sealed class
|
MemoryTextStream
|
extends
|
TextStreamBase
|
Does this object support read access?
public
override
property
|
CanRead
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
object
supports
reading,
false
if
not. |
||
implements
|
TextStreamBase.CanRead
|
Does this binary object support write access?
public
override
property
|
CanWrite
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
object
supports
writing,
false
if
not. |
||
implements
|
TextStreamBase.CanWrite
|
Returns the lifecycle state of this object.
public
virtual
property
|
LifecycleState
{
get
}
|
||
type
|
LifecycleState
|
||
value
|
The lifecycle state. | ||
inherited
|
Disposable.LifecycleState
|
Returns a Path object that represents the file path this object is associated with.
public
override
property
|
PathInfo
{
get
}
|
||
type
|
Path
|
||
value
|
|
The path info. | |
implements
|
TextStreamBase.PathInfo
|
Remarks:
Objects that do not have a meaningful file path association simply return Unknown.
Creates a new instance of MemoryTextStream.
public
constructor
|
MemoryTextStream
(int64 initialCapacity = 1024)
|
||
params
|
initialCapacity
|
[>=0]
|
The
initial
buffer
size,
in
characters.
Defaults
to
1024 .
|
Remarks:
The stream will be in write mode.
See also:
FlipAcquires a strong reference to this disposable object.
[OwnerReturn, ThreadSafe]
|
||||
public
method
|
AcquireTry
()
|
|||
type
|
IDisposable
|
|||
returns
|
this
if
a
new
strong
reference
has
been
acquired,
null
if
this
object
is
already
being
disposed.
|
|||
inherited
|
Disposable.AcquireTry
|
Remarks:
The object will not be actually disposed by calls to Dispose when there is at least one strong reference left. Code that calls the AcquireTry method is responsible for calling the Dispose method accordingly.
This method is not intended to be used in performance-critical code. It should only be used to high-level resource management.
Copies all remaining data in the given object to this object.
public
virtual
method
|
CopyFrom
(ITextStream stream)
|
||
params
|
stream
|
[not-null]
|
The object. |
inherited
|
TextStreamBase.CopyFrom
|
Copies all remaining data in this object to the given object.
public
virtual
method
|
CopyTo
(ITextStream stream)
|
||
params
|
stream
|
[not-null]
|
The object. |
inherited
|
TextStreamBase.CopyTo
|
Releases all resources held by this object if there are no more strong references to it, decrements the reference counter by one otherwise.
[Dispose, OwnerThis, ThreadSafe]
|
||||
public
method
|
Dispose
()
|
|||
inherited
|
Disposable.Dispose
|
Remarks:
The Dispose method silently returns if the object has already been disposed.
Flips this memory stream so that it reads back the data that has been written to it.
public
method
|
Flip
()
|
||
type
|
MemoryTextStream
|
||
returns
|
|
this |
Remarks:
When calling this method, the stream must be in write mode. After returning, the stream will be in read mode.
See also:
ToStringFlushes all cached data.
public
override
method
|
Flush
()
|
||
implements
|
TextStreamBase.Flush
|
Remarks:
Performing a flush may result in I/O work. Depending on the semantics of the implementing class, this work may need to be wrapped in special Begin / End method calls. See the documentation of the implementing classes for details.
In case this object represents a read-only resource, calling the Flush method has no effect.
Creates a new instance of MemoryTextStream that reads the given text.
[OwnerReturn]
|
||||
public
static
method
|
For
(string chars)
|
|||
type
|
MemoryTextStream
|
|||
params
|
chars
|
[not-null]
|
The text to read. | |
returns
|
|
The created text stream. |
Remarks:
The stream will be in read mode.
Creates a new instance of MemoryTextStream that reads the given text.
[OwnerReturn]
|
||||
public
static
method
|
For
(char[] chars)
|
|||
type
|
MemoryTextStream
|
|||
params
|
chars
|
[not-null]
|
The text to read. | |
returns
|
|
The created text stream. |
Remarks:
The stream will be in read mode.
Creates a new instance of MemoryTextStream that reads the given text.
[OwnerReturn]
|
||||
public
static
method
|
For
(string chars,
int32 offset,
int32 count)
|
|||
type
|
MemoryTextStream
|
|||
params
|
chars
|
[not-null]
|
The text to read. | |
offset
|
[>=0]
|
Offset into chars to first character to read. | ||
count
|
[>=0]
|
Total number of characters to read. | ||
returns
|
|
The created text stream. |
Remarks:
The stream will be in read mode.
Creates a new instance of MemoryTextStream that reads the given text.
[OwnerReturn]
|
||||
public
static
method
|
For
(char[] chars,
int32 offset,
int32 count)
|
|||
type
|
MemoryTextStream
|
|||
params
|
chars
|
[not-null]
|
The text to read. | |
offset
|
[>=0]
|
Offset into chars to first character to read. | ||
count
|
[>=0]
|
Total number of characters to read. | ||
returns
|
|
The created text stream. |
Remarks:
The stream will be in read mode.
Reads a number of characters from the stream.
public
method
|
Read
(char[] chars,
int32 offset = 0,
int32 count = -1)
|
||
type
|
int32
|
||
params
|
chars
|
[not-null]
|
The buffer where the read characters will be stored. |
offset
|
[0..chars.Length]
|
Offset
into
chars.
Defaults
to
0 .
|
|
count
|
[-1..chars.Length-offset]
|
Number
of
characters
to
read.
If
-1 ,
characters
will
be
read
up
to
the
end
of
chars.
Defaults
to
-1 .
|
|
returns
|
|
The
number
of
characters
that
have
been
read
into
chars.
A
value
of
0
indicates
that
the
end
of
the
stream
has
been
reached
(assuming
that
the
given
count
was
greater
than
zero).
|
|
inherited
|
TextStreamBase.Read
|
Remarks:
The number of characters that are read from the stream may be less than the given count, for any reason.
Exceptions:
false
.Reads a single character from the stream.
public
virtual
method
|
ReadChar
()
|
||
type
|
char
|
||
returns
|
The read character. | ||
inherited
|
TextStreamBase.ReadChar
|
Exceptions:
false
.Reads all remaining characters from this stream and disposes this stream afterwards.
[OwnerThis]
|
||||
public
override
method
|
ReadToEnd
()
|
|||
type
|
string
|
|||
returns
|
|
The read string. | ||
overrides
|
TextStreamBase.ReadToEnd
|
Skips the next characters in the stream.
public
override
method
|
Skip
(int64 count)
|
||
params
|
count
|
[>=0]
|
The number of characters to skip. |
implements
|
TextStreamBase.Skip
|
[Pure]
|
||||
public
override
method
|
ToString
()
|
|||
type
|
string
|
Reads a single character from the stream.
public
override
method
|
TryReadChar
()
|
||
type
|
int32
|
||
returns
|
|
The
read
character
or
-1
if
the
end
of
the
stream
has
been
reached.
|
|
implements
|
TextStreamBase.TryReadChar
|
Exceptions:
false
.Writes a number of characters to the stream.
public
method
|
Write
(string chars)
|
||
params
|
chars
|
[not-null]
|
The characters to write. |
inherited
|
TextStreamBase.Write
|
Exceptions:
false
.Writes a number of characters to the stream.
public
method
|
Write
(char[] chars)
|
||
params
|
chars
|
[not-null]
|
The characters to write. |
inherited
|
TextStreamBase.Write
|
Exceptions:
false
.Writes a number of characters to the stream.
public
override
method
|
Write
(string chars,
int32 offset,
int32 count)
|
||
params
|
chars
|
[not-null]
|
The characters to write. |
offset
|
[>=0]
|
Offset into chars. | |
count
|
[>=0]
|
Number of characters to write. | |
implements
|
TextStreamBase.Write
|
Exceptions:
false
.Writes a number of characters to the stream.
public
override
method
|
Write
(char[] chars,
int32 offset,
int32 count)
|
||
params
|
chars
|
[not-null]
|
The characters to write. |
offset
|
[>=0]
|
Offset into chars. | |
count
|
[>=0]
|
Number of characters to write. | |
implements
|
TextStreamBase.Write
|
Exceptions:
false
.Writes a single characters to the stream.
public
override
method
|
WriteChar
(char value)
|
||
params
|
value
|
The character to write. | |
implements
|
TextStreamBase.WriteChar
|
Exceptions:
false
.