public void Write_CanWriteAllBytes(int writeSize) { var segmentSize = 5; var stream = new SegmentWriteStream(segmentSize); for (var i = 0; i < WriteData.Length; i += writeSize) { stream.Write(WriteData, i, Math.Min(writeSize, WriteData.Length - i)); } var segments = stream.GetSegments(); Assert.Equal(WriteData.Length, stream.Length); Assert.Equal((WriteData.Length + segmentSize - 1) / segmentSize, segments.Count); for (var i = 0; i < WriteData.Length; i += segmentSize) { var expectedSegmentSize = Math.Min(segmentSize, WriteData.Length - i); var expectedSegment = new byte[expectedSegmentSize]; for (int j = 0; j < expectedSegmentSize; j++) { expectedSegment[j] = (byte)(i + j); } var segment = segments[i / segmentSize]; Assert.Equal(expectedSegmentSize, segment.Length); Assert.True(expectedSegment.SequenceEqual(segment)); } }
public override void Write(byte[] buffer, int offset, int count) { try { _startResponseCallback(); _innerStream.Write(buffer, offset, count); } catch { DisableBuffering(); throw; } if (BufferingEnabled) { if (_segmentWriteStream.Length + count > _maxBufferSize) { DisableBuffering(); } else { _segmentWriteStream.Write(buffer, offset, count); } } }