Inheritance: Stream, ICloneable
Example #1
0
        public static BufferListStream Create(Stream stream, int segmentSize, bool forceCopyStream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            BufferListStream bufferStream;

            if (stream is BufferListStream && !forceCopyStream)
            {
                bufferStream = (BufferListStream)((BufferListStream)stream).Clone();
            }
            else
            {
                int length;
                stream.Position = 0;
                bufferStream    = new BufferListStream(ReadStream(stream, segmentSize, out length));
            }

            return(bufferStream);
        }
Example #2
0
        public static ArraySegment <byte>[] ReadStream(Stream stream, int segmentSize, out int length)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            ArraySegment <byte>[] result;
            BufferListStream      bufferListStream = stream as BufferListStream;

            if (bufferListStream != null)
            {
                result = bufferListStream.bufferList.ToArray();
                length = (int)bufferListStream.length;
            }
            else
            {
                length = 0;
                List <ArraySegment <byte> > buffers = new List <ArraySegment <byte> >();
                while (true)
                {
                    byte[] buffer    = new byte[segmentSize];
                    int    bytesRead = stream.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                    {
                        break;
                    }

                    buffers.Add(new ArraySegment <byte>(buffer, 0, bytesRead));
                    length += bytesRead;
                }

                result = buffers.ToArray();
            }

            return(result);
        }
Example #3
0
 public BrokerMessage(AmqpMessage message)
 {
     this.stream = (BufferListStream)message.ToStream();
     foreach (var buffer in message.RawByteBuffers) buffer.Clone();
     this.RawByteBuffers = message.RawByteBuffers;
 }
Example #4
0
        public static BufferListStream Create(Stream stream, int segmentSize, bool forceCopyStream)
        {
            if (stream == null)
            {
                throw Fx.Exception.ArgumentNull("stream");
            }

            BufferListStream bufferStream;
            if (stream is BufferListStream && !forceCopyStream)
            {
                bufferStream = (BufferListStream)((BufferListStream)stream).Clone();
            }
            else
            {
                int length;
                stream.Position = 0;
                bufferStream = new BufferListStream(ReadStream(stream, segmentSize, out length));
            }

            return bufferStream;
        }