Example #1
0
		bool WriteBuffer()
		{
			bool result;
			if (result = this.backend.Write(buffer.ToArray()))
				buffer = null;
			return result;
		}
Example #2
0
		public Collection.IVector<byte> Read()
		{
			lock (this.peekedLock)
			{
				Collection.IVector<byte> result = this.peeked ?? this.RawRead();
				this.peeked = null;
				return result;
			}
		}
Example #3
0
		public virtual bool Close()
		{
			bool result;
			if (result = this.buffer.NotNull())
			{
				if (this.EscalateClose && this.buffer is IDisposable)
					(this.buffer as IDisposable).Dispose();
				this.buffer = null;
			}
			return result;
		}
Example #4
0
		public override int Read(byte[] buffer, int offset, int count)
		{
			if (this.readBuffer.IsNull())
				this.readBuffer = this.backend.Read();
			Collection.IVector<byte> chunk;
			if (this.readBuffer.Count > count)
			{
				chunk = this.readBuffer.Slice(0, count);
				this.readBuffer = this.readBuffer.Slice(count, this.readBuffer.Count);
			}
			else
			{
				chunk = this.readBuffer;
				this.readBuffer = null;
			}
			int result = 0;
			foreach (byte b in chunk) // TODO: replace with use of bulk copy interface on IVector<T>
				buffer[offset + result++] = b;
			this.Position += result;
			return result;
		}
Example #5
0
		public bool Write(System.Collections.Generic.IEnumerable<byte> buffer)
		{
			this.buffer = this.buffer.Merge(buffer.ToArray());
			return !this.AutoFlush || this.Flush();
		}
Example #6
0
		byte? IByteInDevice.Read()
		{
			lock (this.peekedLock)
			{
				var peeked = this.Peek();
				byte? result;
				if (peeked.NotNull() && peeked.Count > 0)
				{
					result = peeked[0];
					this.peeked = peeked.Count > 1 ? peeked.Slice(1) : null;
				}
				else
					result = null;
				return result;
			}
		}
Example #7
0
		public Collection.IVector<byte> Peek()
		{
			lock (this.peekedLock)
				return this.peeked ?? (this.peeked = this.RawRead());
		}
Example #8
0
		public void Append(Collection.IVector<byte> buffer)
		{
			this.buffer = this.buffer.Merge(buffer);
		}
Example #9
0
		protected BufferByteInDevice(Collection.IVector<byte> buffer)
		{
			this.EscalateClose = true;
			this.buffer = buffer;
			this.Resource = "buffer:///";
		}
Example #10
0
		public bool Write(Collection.IVector<byte> buffer)
		{
			lock (this.Lock)
				this.Buffer = this.Buffer.Merge(buffer);
			return true;
		}