C# Class Redzen.IO.StreamHelper

General purpose helper methods for working with streams.
Mostrar archivo Open project: colgreen/Redzen

Public Methods

Method Description
Copy ( Stream inputStream, Stream outputStream ) : void

Copy all bytes from an input stream into an output stream until the end of the input stream is reached.

Note. .NET 4 introduced CopyTo() methods to the stream base class that makes this method unnecessary.

Copy ( Stream inputStream, Stream outputStream, byte buffer ) : void

Copy all bytes from an input stream into an output stream until the end of the input stream is reached.

Note. .NET 4 introduced CopyTo() methods to the stream base class that makes this method unnecessary.

Read ( Stream stream, byte data ) : int

Reads data from a stream into a provided array. Reads up to the length of array and returns the number of bytes read.

Unlike Stream.Read(), this method guarantees to read bytes until the end of stream is reached.

ReadFill ( Stream stream, byte data ) : void

Reads data from a stream into a provided array, filling the array. If the end of the stream is reached before the array is filled then an EndOfStreamException is thrown.

Unlike Stream.Read(), this method guarantees to fill the byte array if the stream has sufficient bytes.

ReadToByteArray ( Stream stream ) : byte[]

Read stream into byte array. Reads until the end of stream is reached and returns entire stream contents as a new byte array.

Method Details

Copy() public static method

Copy all bytes from an input stream into an output stream until the end of the input stream is reached.
Note. .NET 4 introduced CopyTo() methods to the stream base class that makes this method unnecessary.
public static Copy ( Stream inputStream, Stream outputStream ) : void
inputStream System.IO.Stream The input stream to read bytes from.
outputStream System.IO.Stream The output stream to write bytes into.
return void

Copy() public static method

Copy all bytes from an input stream into an output stream until the end of the input stream is reached.
Note. .NET 4 introduced CopyTo() methods to the stream base class that makes this method unnecessary.
public static Copy ( Stream inputStream, Stream outputStream, byte buffer ) : void
inputStream System.IO.Stream The input stream to read bytes from.
outputStream System.IO.Stream The output stream to write bytes into.
buffer byte A pre-allocated byte buffer.
return void

Read() public static method

Reads data from a stream into a provided array. Reads up to the length of array and returns the number of bytes read.
Unlike Stream.Read(), this method guarantees to read bytes until the end of stream is reached.
public static Read ( Stream stream, byte data ) : int
stream System.IO.Stream The stream to read data from.
data byte The array to read bytes into.
return int

ReadFill() public static method

Reads data from a stream into a provided array, filling the array. If the end of the stream is reached before the array is filled then an EndOfStreamException is thrown.
Unlike Stream.Read(), this method guarantees to fill the byte array if the stream has sufficient bytes.
public static ReadFill ( Stream stream, byte data ) : void
stream System.IO.Stream The stream to read data from.
data byte The array to read bytes into.
return void

ReadToByteArray() public static method

Read stream into byte array. Reads until the end of stream is reached and returns entire stream contents as a new byte array.
public static ReadToByteArray ( Stream stream ) : byte[]
stream System.IO.Stream The stream to read data from.
return byte[]