Class StreamUtilities
Содержит служебные методы для работы с потоками.
Inheritance
Inherited Members
Namespace: Terrasoft.Common
Assembly: Terrasoft.Common.dll
Syntax
public static class StreamUtilities
Fields
ReadStreamBufferLength
Количество байтов, которое должно быть считано из текущего потока.
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 |
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)
Строковое представление содержимого потока.
Declaration
public static string GetStreamContent(Stream source)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | source | Поток. |
Returns
Type | Description |
---|---|
System.String | Содержимое потока в виде строки (от текущего положения до конца). |
Remarks
Для чтения содержимого потока используется стандартный метод ReadToEnd()
класса System.IO.StreamReader.
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 |
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)
Сохранение потока в файл.
Declaration
public static void SaveToFile(this Stream source, string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | source | Поток - источник. |
System.String | filePath | Путь к файлу. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | При передаче в качестве параметра |
Write(Stream, Stream)
Запись в поток.
Declaration
public static void Write(this Stream source, Stream value)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | source | Поток - источник. |
System.IO.Stream | value | Поток - приемник. |
Remarks
Расширяемый метод
Запись в поток - приемник осуществляется блоками по Terrasoft.Common.StreamUtilities.CopiedStreamBufferLength байт. После записи текущая позиция в потоке - источнике возвращается в исходное положение.
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. |