Esempio n. 1
0
        /// <summary>
        /// Reads the specified number of bytes into the buffer.
        /// </summary>
        /// <param name="buffer">The buffer to store the read bytes.</param>
        /// <param name="offset">The offset within the buffer to begin storing read bytes.</param>
        /// <param name="count">The number of bytes to read.</param>
        public void ReadBytes(byte[] buffer, int offset, int count)
        {
            int bytesRead = stream.Read(buffer, offset, count);

            // stream.Read returns an integer that specifies how many bytes were actually read.
            // This number does not have to match the number of bytes requested by the count parameter.
            // If there is a discrepancy then throw an exception to notify the user the stream might be corrupted.
            if (bytesRead != count)
            {
                throw DataStreamException.UnexpectedEOS(count, bytesRead);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Reads an unsigned byte from the underlying stream.
        /// </summary>
        /// <returns>The value read from the underlying stream.</returns>
        public byte ReadByte()
        {
            int byteRead = stream.ReadByte();

            // If an attempt is made to read a byte at the end of the stream -1 is returned.
            if (byteRead == -1)
            {
                throw DataStreamException.UnexpectedEOS(1, 0);
            }

            return((byte)byteRead);
        }