Search Results for

    Show / Hide Table of Contents

    Class StreamUtil

    Static utility helpers for working with streams: file/stream/memory conversions, writing strings, primitive-to-byte-array conversions and (when ZLib is enabled) stream compression and decompression.

    Inheritance
    object
    StreamUtil
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: Reportman.Drawing
    Assembly: Reportman.Drawing.dll
    Syntax
    public class StreamUtil

    Constructors

    View Source

    StreamUtil()

    Declaration
    public StreamUtil()

    Fields

    View Source

    CRLFarray

    Declaration
    public static byte[] CRLFarray
    Field Value
    Type Description
    byte[]
    View Source

    DEFAULT_BUFFER_SIZE

    Default buffer size for buffered applications

    Declaration
    public const int DEFAULT_BUFFER_SIZE = 65535
    Field Value
    Type Description
    int
    View Source

    LFarray

    Declaration
    public static byte[] LFarray
    Field Value
    Type Description
    byte[]

    Methods

    View Source

    BoolToByteArray(bool)

    Converts a bool to a byte array

    Declaration
    public static byte[] BoolToByteArray(bool avalue)
    Parameters
    Type Name Description
    bool avalue
    Returns
    Type Description
    byte[]
    View Source

    ByteArrayToInt(byte[], int)

    Converts a byte array to an int value

    Declaration
    public static int ByteArrayToInt(byte[] b1, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int alen
    Returns
    Type Description
    int
    View Source

    ByteArrayToInt(byte[], int, int)

    Converts a byte array to an int value

    Declaration
    public static int ByteArrayToInt(byte[] b1, int index, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int index
    int alen
    Returns
    Type Description
    int
    View Source

    ByteArrayToInt64(byte[], int, int)

    Converts a byte array to an int64 value

    Declaration
    public static long ByteArrayToInt64(byte[] b1, int index, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int index
    int alen
    Returns
    Type Description
    long
    View Source

    ByteArrayToLong(byte[], int)

    Converts a byte array to a long value

    Declaration
    public static long ByteArrayToLong(byte[] b1, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int alen
    Returns
    Type Description
    long
    View Source

    ByteArrayToLong(byte[], int, int)

    Converts a byte array to a long value

    Declaration
    public static long ByteArrayToLong(byte[] b1, int index, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int index
    int alen
    Returns
    Type Description
    long
    View Source

    ByteArrayToShort(byte[], int)

    Converts a byte array to a short value

    Declaration
    public static short ByteArrayToShort(byte[] b1, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int alen
    Returns
    Type Description
    short
    View Source

    ByteArrayToShort(byte[], int, int)

    Converts a byte array to a short value

    Declaration
    public static short ByteArrayToShort(byte[] b1, int index, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int index
    int alen
    Returns
    Type Description
    short
    View Source

    ByteArrayToStream(byte[])

    Converts a byte array to a MemoryStream

    Declaration
    public static MemoryStream ByteArrayToStream(byte[] b1)
    Parameters
    Type Name Description
    byte[] b1
    Returns
    Type Description
    MemoryStream
    View Source

    ByteArrayToString(byte[], int)

    Converts a byte array to a string (not unicode)

    Declaration
    public static string ByteArrayToString(byte[] b1, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int alen
    Returns
    Type Description
    string
    View Source

    ByteArrayToString(byte[], int, bool)

    Converts a byte array to a string, choosing unicode

    Declaration
    public static string ByteArrayToString(byte[] b1, int alen, bool unicode)
    Parameters
    Type Name Description
    byte[] b1
    int alen
    bool unicode
    Returns
    Type Description
    string
    View Source

    ByteArrayToString(byte[], int, int)

    Converts a byte array to a string (not unicode)

    Declaration
    public static string ByteArrayToString(byte[] b1, int nindex, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int nindex
    int alen
    Returns
    Type Description
    string
    View Source

    ByteArrayToUInt(byte[], int, int)

    Converts a byte array to an uint value

    Declaration
    public static uint ByteArrayToUInt(byte[] b1, int index, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int index
    int alen
    Returns
    Type Description
    uint
    View Source

    ByteArrayToUShort(byte[], int, int)

    Converts a byte array to an ushort value

    Declaration
    public static ushort ByteArrayToUShort(byte[] b1, int index, int alen)
    Parameters
    Type Name Description
    byte[] b1
    int index
    int alen
    Returns
    Type Description
    ushort
    View Source

    ByteToByteArray(byte)

    Converts a byte to a byte array

    Declaration
    public static byte[] ByteToByteArray(byte avalue)
    Parameters
    Type Name Description
    byte avalue
    Returns
    Type Description
    byte[]
    View Source

    CompareArrayContent(byte[], byte[])

    Compare the content of two byte arrays, returns true if the content is the same

    Declaration
    public static bool CompareArrayContent(byte[] b1, byte[] b2)
    Parameters
    Type Name Description
    byte[] b1
    byte[] b2
    Returns
    Type Description
    bool
    View Source

    CompressFile(string, string)

    Declaration
    public static void CompressFile(string source, string destination)
    Parameters
    Type Name Description
    string source
    string destination
    View Source

    CompressStream(MemoryStream, MemoryStream, bool)

    Compress the first memory stream into the second memory stream, option for optimize size

    Declaration
    public static void CompressStream(MemoryStream memstream, MemoryStream dest, bool optimizesize)
    Parameters
    Type Name Description
    MemoryStream memstream
    MemoryStream dest
    bool optimizesize
    View Source

    CompressStream(Stream, MemoryStream)

    Compress the first memory stream into the second memory stream

    Declaration
    public static void CompressStream(Stream memstream, MemoryStream dest)
    Parameters
    Type Name Description
    Stream memstream
    MemoryStream dest
    View Source

    CompressStreamAsync(MemoryStream, MemoryStream)

    Compress the first memory stream into the second memory stream

    Declaration
    public static Task CompressStreamAsync(MemoryStream memstream, MemoryStream dest)
    Parameters
    Type Name Description
    MemoryStream memstream
    MemoryStream dest
    Returns
    Type Description
    Task
    View Source

    CompressStreamAsync(MemoryStream, MemoryStream, bool, bool, CancellationTokenSource)

    Declaration
    public static Task<TaskCompressResult> CompressStreamAsync(MemoryStream memstream, MemoryStream dest, bool optimizesize, bool disposeSource, CancellationTokenSource cancelSource)
    Parameters
    Type Name Description
    MemoryStream memstream
    MemoryStream dest
    bool optimizesize
    bool disposeSource
    CancellationTokenSource cancelSource
    Returns
    Type Description
    Task<TaskCompressResult>
    View Source

    CompressStreamGZip(MemoryStream, MemoryStream)

    Compress the first memory stream into the second memory stream using Gzip

    Declaration
    public static void CompressStreamGZip(MemoryStream memstream, MemoryStream dest)
    Parameters
    Type Name Description
    MemoryStream memstream
    MemoryStream dest
    View Source

    CompressStreamGZipAsync(MemoryStream, MemoryStream)

    Compress the first memory stream into the second memory stream using Gzip

    Declaration
    public static Task CompressStreamGZipAsync(MemoryStream memstream, MemoryStream dest)
    Parameters
    Type Name Description
    MemoryStream memstream
    MemoryStream dest
    Returns
    Type Description
    Task
    View Source

    CompressStreamTask(MemoryStream, MemoryStream, bool, bool, CancellationTokenSource)

    Declaration
    public static Task<TaskCompressResult> CompressStreamTask(MemoryStream memstream, MemoryStream dest, bool optimizesize, bool disposeSource, CancellationTokenSource cancelSource)
    Parameters
    Type Name Description
    MemoryStream memstream
    MemoryStream dest
    bool optimizesize
    bool disposeSource
    CancellationTokenSource cancelSource
    Returns
    Type Description
    Task<TaskCompressResult>
    View Source

    DeCompressBuffer(byte[], int, Stream)

    Dercompress the first memory stream into the second memory stream

    Declaration
    public static void DeCompressBuffer(byte[] buffer, int count, Stream dest)
    Parameters
    Type Name Description
    byte[] buffer
    int count
    Stream dest
    View Source

    DeCompressBuffer(byte[], int, Stream, ProgressEvent)

    Dercompress the first memory stream into the second memory stream

    Declaration
    public static void DeCompressBuffer(byte[] buffer, int count, Stream dest, ProgressEvent progevent)
    Parameters
    Type Name Description
    byte[] buffer
    int count
    Stream dest
    ProgressEvent progevent
    View Source

    DeCompressBufferAsync(byte[], int, Stream)

    Dercompress the first memory stream into the second memory stream

    Declaration
    public static Task DeCompressBufferAsync(byte[] buffer, int count, Stream dest)
    Parameters
    Type Name Description
    byte[] buffer
    int count
    Stream dest
    Returns
    Type Description
    Task
    View Source

    DeCompressBufferAsync(byte[], int, Stream, ProgressEvent)

    net Dercompress the first memory stream into the second memory stream

    Declaration
    public static Task DeCompressBufferAsync(byte[] buffer, int count, Stream dest, ProgressEvent progevent)
    Parameters
    Type Name Description
    byte[] buffer
    int count
    Stream dest
    ProgressEvent progevent
    Returns
    Type Description
    Task
    View Source

    DeCompressBufferGZip(byte[], int, int, Stream)

    Dercompress the first memory stream into the second memory stream

    Declaration
    public static void DeCompressBufferGZip(byte[] buffer, int offset, int count, Stream dest)
    Parameters
    Type Name Description
    byte[] buffer
    int offset
    int count
    Stream dest
    View Source

    DeCompressBufferGZipAsync(byte[], int, int, Stream)

    Dercompress the first memory stream into the second memory stream

    Declaration
    public static Task DeCompressBufferGZipAsync(byte[] buffer, int offset, int count, Stream dest)
    Parameters
    Type Name Description
    byte[] buffer
    int offset
    int count
    Stream dest
    Returns
    Type Description
    Task
    View Source

    DeCompressFile(string, string)

    Declaration
    public static void DeCompressFile(string source, string destination)
    Parameters
    Type Name Description
    string source
    string destination
    View Source

    DeCompressStream(MemoryStream, MemoryStream)

    Dercompress the first memory stream into the second memory stream

    Declaration
    public static void DeCompressStream(MemoryStream memstream, MemoryStream dest)
    Parameters
    Type Name Description
    MemoryStream memstream
    MemoryStream dest
    View Source

    DecompressStreamGZip(Stream, Stream)

    Declaration
    public static void DecompressStreamGZip(Stream origin, Stream dest)
    Parameters
    Type Name Description
    Stream origin
    Stream dest
    View Source

    DecompressStreamGZipAsync(Stream, Stream)

    Declaration
    public static Task DecompressStreamGZipAsync(Stream origin, Stream dest)
    Parameters
    Type Name Description
    Stream origin
    Stream dest
    Returns
    Type Description
    Task
    View Source

    FileInUse(string)

    Check for a file if in use return true

    Declaration
    public static bool FileInUse(string path)
    Parameters
    Type Name Description
    string path
    Returns
    Type Description
    bool
    View Source

    FileToMemoryStream(string)

    Generates a MemoryStream from a file

    Declaration
    public static MemoryStream FileToMemoryStream(string filename)
    Parameters
    Type Name Description
    string filename
    Returns
    Type Description
    MemoryStream
    View Source

    FileToMemoryStreamAsync(string)

    Generates a MemoryStream from a file

    Declaration
    public static Task<MemoryStream> FileToMemoryStreamAsync(string filename)
    Parameters
    Type Name Description
    string filename
    Returns
    Type Description
    Task<MemoryStream>
    View Source

    GetFiles(string, string, SearchOption)

    Declaration
    public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption)
    Parameters
    Type Name Description
    string path
    string searchPattern
    SearchOption searchOption
    Returns
    Type Description
    string[]
    View Source

    Int64ToByteArray(long)

    Converts an int to a byte array

    Declaration
    public static byte[] Int64ToByteArray(long avalue)
    Parameters
    Type Name Description
    long avalue
    Returns
    Type Description
    byte[]
    View Source

    IntToByteArray(int)

    Converts an int to a byte array

    Declaration
    public static byte[] IntToByteArray(int avalue)
    Parameters
    Type Name Description
    int avalue
    Returns
    Type Description
    byte[]
    View Source

    IsCompressed(byte[])

    Check if the stream is a compressed stream

    Declaration
    public static bool IsCompressed(byte[] buf)
    Parameters
    Type Name Description
    byte[] buf
    Returns
    Type Description
    bool
    View Source

    IsCompressed(MemoryStream)

    Check if the stream is a compressed stream

    Declaration
    public static bool IsCompressed(MemoryStream mems)
    Parameters
    Type Name Description
    MemoryStream mems
    Returns
    Type Description
    bool
    View Source

    LongToByteArray(long)

    Converts a long value to a byte array to a long value

    Declaration
    public static byte[] LongToByteArray(long avalue)
    Parameters
    Type Name Description
    long avalue
    Returns
    Type Description
    byte[]
    View Source

    MemoryStreamToFile(MemoryStream, string)

    Generate a file from a memory stream

    Declaration
    public static void MemoryStreamToFile(MemoryStream memstream, string filename)
    Parameters
    Type Name Description
    MemoryStream memstream
    string filename
    View Source

    SWriteLine(Stream, string, bool)

    Write a string to a stream, the string should contain only single byte characters

    Declaration
    public static void SWriteLine(Stream astream, string astring, bool includeCR = false)
    Parameters
    Type Name Description
    Stream astream
    string astring
    bool includeCR
    View Source

    ShortToByteArray(int)

    Converts a short to a byte array

    Declaration
    public static byte[] ShortToByteArray(int avalue)
    Parameters
    Type Name Description
    int avalue
    Returns
    Type Description
    byte[]
    View Source

    StreamToFile(Stream, string, bool)

    Generate a file from a stream

    Declaration
    public static void StreamToFile(Stream memstream, string filename, bool overwrite)
    Parameters
    Type Name Description
    Stream memstream
    string filename
    bool overwrite
    View Source

    StreamToFileAsync(Stream, string, bool)

    Generate a file from a stream

    Declaration
    public static void StreamToFileAsync(Stream memstream, string filename, bool overwrite)
    Parameters
    Type Name Description
    Stream memstream
    string filename
    bool overwrite
    View Source

    StreamToHex(Stream)

    Transforms stream content to string representation as hexadecimal bytes

    Declaration
    public static string StreamToHex(Stream astream)
    Parameters
    Type Name Description
    Stream astream
    Returns
    Type Description
    string
    View Source

    StreamToMemoryStream(Stream)

    Generates a MemoryStream from any Stream input

    Declaration
    public static MemoryStream StreamToMemoryStream(Stream astream)
    Parameters
    Type Name Description
    Stream astream
    Returns
    Type Description
    MemoryStream
    View Source

    StreamToMemoryStream(Stream, int)

    Generates a MemoryStream from any Stream input

    Declaration
    public static MemoryStream StreamToMemoryStream(Stream astream, int bufsize)
    Parameters
    Type Name Description
    Stream astream

    Source stream

    int bufsize

    Buffer size can be specified size for performance enhacement when handling long streams. You can specify 0 value, so the DEFAULT_BUFFER_SIZE (65535) will be used. Note that standard input does not allow reading long segments so keep the default value if you don't know the source stream procedence

    Returns
    Type Description
    MemoryStream

    The resulting memory stream

    View Source

    StreamToMemoryStreamAsync(Stream, int)

    Generates a MemoryStream from any Stream input

    Declaration
    public static Task<MemoryStream> StreamToMemoryStreamAsync(Stream astream, int bufsize)
    Parameters
    Type Name Description
    Stream astream

    Source stream

    int bufsize

    Buffer size can be specified size for performance enhacement when handling long streams. You can specify 0 value, so the DEFAULT_BUFFER_SIZE (65535) will be used. Note that standard input does not allow reading long segments so keep the default value if you don't know the source stream procedence

    Returns
    Type Description
    Task<MemoryStream>

    The resulting memory stream

    View Source

    StringToByteArray(string, int)

    Converts a string (not unicode) to a byte array the array is created with the first byte of the char value only ANSI alowed

    Declaration
    public static byte[] StringToByteArray(string avalue, int length)
    Parameters
    Type Name Description
    string avalue
    int length
    Returns
    Type Description
    byte[]
    View Source

    StringToByteArray(string, int, bool)

    Converts a string to a byte array, choosing unicode or not

    Declaration
    public static byte[] StringToByteArray(string avalue, int length, bool unicode)
    Parameters
    Type Name Description
    string avalue
    int length
    bool unicode
    Returns
    Type Description
    byte[]
    View Source

    StringToByteArray(string, int, int)

    Converts a string (not unicode) to a byte array

    Declaration
    public static byte[] StringToByteArray(string avalue, int length, int codepage)
    Parameters
    Type Name Description
    string avalue
    int length
    int codepage
    Returns
    Type Description
    byte[]
    View Source

    WriteCharArrayToStream(char[], int, Stream)

    Writes a string to a stream formatted as multibyte UFT8 encondig

    Declaration
    public static int WriteCharArrayToStream(char[] chars, int len, Stream astream)
    Parameters
    Type Name Description
    char[] chars
    int len
    Stream astream
    Returns
    Type Description
    int
    View Source

    WriteStringToStream(string, Stream, Encoding)

    Writes a string to a stream formatted as multibyte UFT8 encondig

    Declaration
    public static int WriteStringToStream(string astring, Stream astream, Encoding nencoding)
    Parameters
    Type Name Description
    string astring
    Stream astream
    Encoding nencoding
    Returns
    Type Description
    int
    View Source

    WriteStringToUTF8Stream(string, Stream)

    Writes a string to a stream formatted as multibyte UFT8 encondig

    Declaration
    public static int WriteStringToUTF8Stream(string astring, Stream astream)
    Parameters
    Type Name Description
    string astring
    Stream astream
    Returns
    Type Description
    int
    View Source

    WriteTo(Stream, Stream, int)

    Declaration
    public static void WriteTo(Stream from, Stream to, int bufSize = 32000)
    Parameters
    Type Name Description
    Stream from
    Stream to
    int bufSize
    • View Source
    In this article
    Back to top Generated by DocFX