opensim/OpenSim/Framework/Util.cs
/// <summary>
/// Reads a known number of bytes from a stream.
/// Throws EndOfStreamException if the stream doesn't contain enough data.
/// </summary>
/// <param name="stream">The stream to read data from</param>
/// <param name="data">The array to write bytes into. The array
/// will be completely filled from the stream, so an appropriate
/// size must be given.</param>
Reads a known number of bytes from a stream.
Throws EndOfStreamException if the stream doesn't contain enough data.
Reads a known number of bytes from a stream . Throws EndOfStreamException if the stream doesn ' t contain enough data .
public static void ReadStream(Stream stream, byte[] data)
        {
            int offset = 0;
            int remaining = data.Length;
            while (remaining > 0)
            {
                int read = stream.Read(data, offset, remaining);
                if (read <= 0)
                    throw new EndOfStreamException(String.Format("End of stream reached with {0} bytes left to read", remaining));
                remaining -= read;
                offset += read;
            }
        }
public static void ReadStream ( Stream stream , byte [ ] data ) { int offset = 0 ; int remaining = data . Length ; while ( remaining > 0 ) { int read = stream . Read ( data , offset , remaining ) ; if ( read <= 0 ) throw new EndOfStreamException ( String . Format ( " " , remaining ) ) ; remaining -= read ; offset += read ; } }
Reads a known number of bytes from a stream.
Reads a known number of bytes from a stream .
stream
Stream
The stream to read data from
The stream to read data from
data
byte[]
The array to write bytes into. The array
will be completely filled from the stream, so an appropriate
size must be given.
The array to write bytes into . The array will be completely filled from the stream so an appropriate size must be given .