MySql.Data.MySqlClient.MySqlStream.ReadFully C# (CSharp) Method

ReadFully() static private method

Reads the specified number of bytes from the stream and stores them at given offset in the buffer. Throws EndOfStreamException if not all bytes can be read.
static private ReadFully ( Stream stream, byte buffer, int offset, int count ) : void
stream Stream Stream to read from
buffer byte Array to store bytes read from the stream
offset int The offset in buffer at which to begin storing the data read from the current stream.
count int Number of bytes to read
return void
    internal static void ReadFully(Stream stream, byte[] buffer, int offset, int count)
    {
      int numRead = 0;
      int numToRead = count;
      while (numToRead > 0)
      {
        int read = stream.Read(buffer, offset + numRead, numToRead);
        if (read == 0)
        {
          throw new EndOfStreamException();
        }
        numRead += read;
        numToRead -= read;
      }
    }

Usage Example

コード例 #1
0
        private void ReadNextPacket(int len)
        {
            inBuffer = inBufferRef.Target as byte[];

            if (inBuffer == null || inBuffer.Length < len)
            {
                inBuffer = new byte[len];
            }
            MySqlStream.ReadFully(baseStream, inBuffer, 0, len);
        }
All Usage Examples Of MySql.Data.MySqlClient.MySqlStream::ReadFully