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.
Assembly: Reportman.Drawing.dll
Syntax
Constructors
View Source
StreamUtil()
Declaration
Fields
View Source
CRLFarray
Declaration
public static byte[] CRLFarray
Field Value
View Source
DEFAULT_BUFFER_SIZE
Default buffer size for buffered applications
Declaration
public const int DEFAULT_BUFFER_SIZE = 65535
Field Value
View Source
LFarray
Declaration
public static byte[] LFarray
Field Value
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
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
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
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
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
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
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
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
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
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
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
Returns
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
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
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
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
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
View Source
CompressFile(string, string)
Declaration
public static void CompressFile(string source, string destination)
Parameters
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
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
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
Returns
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
Returns
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
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
Returns
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
Returns
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
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
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
Returns
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
Returns
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
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
Returns
View Source
DeCompressFile(string, string)
Declaration
public static void DeCompressFile(string source, string destination)
Parameters
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
View Source
DecompressStreamGZip(Stream, Stream)
Declaration
public static void DecompressStreamGZip(Stream origin, Stream dest)
Parameters
View Source
DecompressStreamGZipAsync(Stream, Stream)
Declaration
public static Task DecompressStreamGZipAsync(Stream origin, Stream dest)
Parameters
Returns
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
View Source
FileToMemoryStream(string)
Generates a MemoryStream from a file
Declaration
public static MemoryStream FileToMemoryStream(string filename)
Parameters
| Type |
Name |
Description |
| string |
filename |
|
Returns
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
View Source
GetFiles(string, string, SearchOption)
Declaration
public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption)
Parameters
Returns
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
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
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
View Source
IsCompressed(MemoryStream)
Check if the stream is a compressed stream
Declaration
public static bool IsCompressed(MemoryStream mems)
Parameters
Returns
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
View Source
MemoryStreamToFile(MemoryStream, string)
Generate a file from a memory stream
Declaration
public static void MemoryStreamToFile(MemoryStream memstream, string filename)
Parameters
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
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
View Source
StreamToFile(Stream, string, bool)
Generate a file from a stream
Declaration
public static void StreamToFile(Stream memstream, string filename, bool overwrite)
Parameters
View Source
StreamToFileAsync(Stream, string, bool)
Generate a file from a stream
Declaration
public static void StreamToFileAsync(Stream memstream, string filename, bool overwrite)
Parameters
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
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
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
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
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
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
View Source
WriteTo(Stream, Stream, int)
Declaration
public static void WriteTo(Stream from, Stream to, int bufSize = 32000)
Parameters