public FileSource(IRefillBuffer <byte[]> buffer, int consumerId) { this.buffer = buffer; this.consumerId = consumerId; length = ((ByteStreamToBlock)buffer.BlockSource).Source.Length; dataInfo = new DataInfo() { GetBlock = () => { while (!buffer.CanRead(consumerId)) { Thread.Sleep(20); } return(buffer.GetBlock(consumerId)); }, Advance = () => { while (!buffer.CanRead(consumerId)) { Thread.Sleep(20); } localStartPosition += buffer.GetBlock(consumerId).Length; dataInfo.Offset = 0; buffer.Advance(consumerId); }, GetLength = () => { return(length); }, GetPosition = () => { return(localStartPosition + dataInfo.Offset); } }; }
public void Skip(Int64 bytes) { if (bytes <= 0 || EOF()) { return; //throw error/warning when bytes < 0 } lock (syncRoot) { Int64 bytesSkipped = Math.Min(buffer.GetBlock(consumerId).Length - dataInfo.Offset, bytes); dataInfo.Offset += bytesSkipped; bytes -= bytesSkipped; byte[] block = buffer.GetBlock(consumerId); if (dataInfo.Offset == block.Length) { dataInfo.Advance(); } while (bytes != 0) { if (bytes > (block.Length - dataInfo.Offset)) { bytes -= block.Length - dataInfo.Offset; localStartPosition += block.Length; dataInfo.Offset = 0; while (!buffer.CanRead(consumerId)) { Thread.Sleep(20); } buffer.Advance(consumerId); if (bytes != 0 && Position == Length) { throw new Exception("Skip: Unexpected EOF"); } block = buffer.GetBlock(consumerId); } else { dataInfo.Offset += Math.Min(bytes, length - Position); //dataInfo.Offset += bytes; bytes = 0; } } } }
private void DummyRead() { bool endOfStream; while (!(endOfStream = b.EndOfStream(consumerId)) && !b.CanRead(consumerId)) { Thread.Sleep(20); } while (!endOfStream) { b.Advance(consumerId); while (!(endOfStream = b.EndOfStream(consumerId)) && !b.CanRead(consumerId)) { Thread.Sleep(20); } } /*while(!b.EndOfStream(consumerId)) { * while(!b.CanRead(consumerId)) Thread.Sleep(20); * b.Advance(consumerId); * }*/ }