/// <summary> /// Reads a sequence of bytes from the stream and advances the position /// within the stream by the number of bytes read. /// </summary> /// <remarks> /// Reads a sequence of bytes from the stream and advances the position /// within the stream by the number of bytes read. /// </remarks> /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many /// bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns> /// <param name="buffer">The buffer to read data into.</param> /// <param name="offset">The offset into the buffer to start reading data.</param> /// <param name="count">The number of bytes to read.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="buffer"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <para><paramref name="offset"/> is less than zero or greater than the length of <paramref name="buffer"/>.</para> /// <para>-or-</para> /// <para>The <paramref name="buffer"/> is not large enough to contain <paramref name="count"/> bytes starting /// at the specified <paramref name="offset"/>.</para> /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The stream has been disposed. /// </exception> /// <exception cref="System.IO.IOException"> /// An I/O error occurred. /// </exception> public override int Read(byte[] buffer, int offset, int count) { ValidateArguments(buffer, offset, count); CheckDisposed(); int dataLeft = dataEndOffset - reader.StreamOffset; int n = Math.Min(dataLeft, count); int nread = n > 0 ? reader.ReadAttributeRawValue(buffer, offset, n) : 0; dataLeft -= nread; if (dataLeft == 0 && valueEndOffset > reader.StreamOffset) { int valueLeft = valueEndOffset - reader.StreamOffset; var buf = ArrayPool <byte> .Shared.Rent(valueLeft); try { reader.ReadAttributeRawValue(buf, 0, valueLeft); } finally { ArrayPool <byte> .Shared.Return(buf); } } return(nread); }
/// <summary> /// Reads a sequence of bytes from the stream and advances the position /// within the stream by the number of bytes read. /// </summary> /// <remarks> /// Reads a sequence of bytes from the stream and advances the position /// within the stream by the number of bytes read. /// </remarks> /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many /// bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns> /// <param name="buffer">The buffer to read data into.</param> /// <param name="offset">The offset into the buffer to start reading data.</param> /// <param name="count">The number of bytes to read.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="buffer"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <para><paramref name="offset"/> is less than zero or greater than the length of <paramref name="buffer"/>.</para> /// <para>-or-</para> /// <para>The <paramref name="buffer"/> is not large enough to contain <paramref name="count"/> bytes starting /// at the specified <paramref name="offset"/>.</para> /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The stream has been disposed. /// </exception> /// <exception cref="System.IO.IOException"> /// An I/O error occurred. /// </exception> public override int Read(byte[] buffer, int offset, int count) { ValidateArguments(buffer, offset, count); CheckDisposed(); int valueLeft = valueEndOffset - reader.StreamOffset; int n = Math.Min(valueLeft, count); return(n > 0 ? reader.ReadAttributeRawValue(buffer, offset, n) : 0); }
/// <summary> /// Reads a sequence of bytes from the stream and advances the position /// within the stream by the number of bytes read. /// </summary> /// <remarks> /// Reads a sequence of bytes from the stream and advances the position /// within the stream by the number of bytes read. /// </remarks> /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many /// bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns> /// <param name="buffer">The buffer to read data into.</param> /// <param name="offset">The offset into the buffer to start reading data.</param> /// <param name="count">The number of bytes to read.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="buffer"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <para><paramref name="offset"/> is less than zero or greater than the length of <paramref name="buffer"/>.</para> /// <para>-or-</para> /// <para>The <paramref name="buffer"/> is not large enough to contain <paramref name="count"/> bytes starting /// at the specified <paramref name="offset"/>.</para> /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The stream has been disposed. /// </exception> /// <exception cref="System.IO.IOException"> /// An I/O error occurred. /// </exception> public override int Read(byte[] buffer, int offset, int count) { ValidateArguments(buffer, offset, count); CheckDisposed(); int dataLeft = dataEndOffset - reader.StreamOffset; int n = Math.Min(dataLeft, count); int nread = n > 0 ? reader.ReadAttributeRawValue(buffer, offset, n) : 0; dataLeft -= nread; if (dataLeft == 0 && valueEndOffset > reader.StreamOffset) { int valueLeft = valueEndOffset - reader.StreamOffset; var buf = new byte[valueLeft]; reader.ReadAttributeRawValue(buf, 0, buf.Length); } return(nread); }