Show / Hide Table of Contents

Class StreamUtilities

Comprises utility methods for working with streams.

Inheritance
System.Object
StreamUtilities
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Terrasoft.Common
Assembly: Terrasoft.Common.dll
Syntax
public static class StreamUtilities

Fields

ReadStreamBufferLength

The number of bytes that must be read from the current stream.

Declaration
public const int ReadStreamBufferLength = 100
Field Value
Type Description
System.Int32

Methods

GetAllBytes(Stream)

Reads all bytes from stream, restores initial position. Please use ReadToEnd(Stream) method when only reading stream content is required.

Declaration
public static byte[] GetAllBytes(this Stream source)
Parameters
Type Name Description
System.IO.Stream source

Source stream.

Returns
Type Description
System.Byte[]

Stream bytes.

Exceptions
Type Condition
System.ArgumentNullException

When source is null.

GetContent(Stream)

Declaration
public static string GetContent(this Stream source)
Parameters
Type Name Description
System.IO.Stream source
Returns
Type Description
System.String

GetStreamContent(Stream)

String view of the stream’s contents.

Declaration
public static string GetStreamContent(Stream source)
Parameters
Type Name Description
System.IO.Stream source

Stream.

Returns
Type Description
System.String

Stream contents shown as string (from the current position and to the end).

Remarks

To read stream’s contents, standard ReadToEnd() method of the System.IO.StreamReader class is used.

IsNullOrEmpty(Stream)

Checking if a stream is null or empty.

Declaration
public static bool IsNullOrEmpty(this Stream source)
Parameters
Type Name Description
System.IO.Stream source

Source stream.

Returns
Type Description
System.Boolean

ReadAllBytes(Stream)

Reads all bytes from beginning of the stream, restores initial position. Please use ReadToEnd(Stream) method when only reading stream content is required. This method should be used only in specific cases, and when source stream supports System.IO.Stream.Position and System.IO.Stream.Length properties.

Declaration
public static byte[] ReadAllBytes(this Stream source)
Parameters
Type Name Description
System.IO.Stream source

Source stream.

Returns
Type Description
System.Byte[]

Stream bytes.

Exceptions
Type Condition
System.ArgumentNullException

When source is null.

ReadToEnd(Stream)

Reads all bytes from stream.

Declaration
public static byte[] ReadToEnd(this Stream source)
Parameters
Type Name Description
System.IO.Stream source
Returns
Type Description
System.Byte[]

SaveToFile(Stream, String)

Saving stream to file.

Declaration
public static void SaveToFile(this Stream source, string filePath)
Parameters
Type Name Description
System.IO.Stream source

Source stream.

System.String filePath

The path to the file.

Exceptions
Type Condition
System.ArgumentNullException

When passing as a parameter source of the null value.

Write(Stream, Stream)

Recording to stream.

Declaration
public static void Write(this Stream source, Stream value)
Parameters
Type Name Description
System.IO.Stream source

Source stream.

System.IO.Stream value

Receiving stream.

Remarks

Extensible method.

Recording to the receiving stream is done in blocks of Terrasoft.Common.StreamUtilities.CopiedStreamBufferLength bytes. After the recording is complete, the position in the source stream returns to its original state.

Write<T>(Stream, T, Func<T, Byte[]>)

Declaration
public static void Write<T>(this Stream source, T value, Func<T, byte[]> func)
Parameters
Type Name Description
System.IO.Stream source
T value
System.Func<T, System.Byte[]> func
Type Parameters
Name Description
T

WriteTo(Stream, Stream)

Copies all the data from one stream into another.

Declaration
public static void WriteTo(this Stream source, Stream targetStream)
Parameters
Type Name Description
System.IO.Stream source

Source stream.

System.IO.Stream targetStream

Target stream.

Back to top Generated by DocFX