public BufferListStream(IList<ArraySegment<byte>> arraySegments)
{
if (arraySegments == null)
{
throw new ArgumentNullException("arraySegments");
}
this.bufferList = arraySegments;
for (int i = this.bufferList.Count - 1; i >= 0; i--)
{
var segment = this.bufferList[i];
if (segment.Count == 0 && this.length > 0)
{
// empty segment in the middle not allowed
throw new ArgumentException("segment" + i);
}
this.length += segment.Count;
}
}