public void WriteByte_CanWriteAllBytes(int segmentSize)
        {
            var stream = new SegmentWriteStream(segmentSize);

            foreach (var datum in WriteData)
            {
                stream.WriteByte(datum);
            }
            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));
            }
        }
Exemplo n.º 2
0
    public override void WriteByte(byte value)
    {
        try
        {
            _innerStream.WriteByte(value);
        }
        catch
        {
            DisableBuffering();
            throw;
        }

        if (BufferingEnabled)
        {
            if (_segmentWriteStream.Length + 1 > _maxBufferSize)
            {
                DisableBuffering();
            }
            else
            {
                _segmentWriteStream.WriteByte(value);
            }
        }
    }