bool WriteBuffer() { bool result; if (result = this.backend.Write(buffer.ToArray())) buffer = null; return result; }
public Collection.IVector<byte> Read() { lock (this.peekedLock) { Collection.IVector<byte> result = this.peeked ?? this.RawRead(); this.peeked = null; return result; } }
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; }
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; }
public bool Write(System.Collections.Generic.IEnumerable<byte> buffer) { this.buffer = this.buffer.Merge(buffer.ToArray()); return !this.AutoFlush || this.Flush(); }
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; } }
public Collection.IVector<byte> Peek() { lock (this.peekedLock) return this.peeked ?? (this.peeked = this.RawRead()); }
public void Append(Collection.IVector<byte> buffer) { this.buffer = this.buffer.Merge(buffer); }
protected BufferByteInDevice(Collection.IVector<byte> buffer) { this.EscalateClose = true; this.buffer = buffer; this.Resource = "buffer:///"; }
public bool Write(Collection.IVector<byte> buffer) { lock (this.Lock) this.Buffer = this.Buffer.Merge(buffer); return true; }