示例#1
0
 /// <inheritdoc/>
 public byte ReadByte(long index)
 {
     streamsLock.EnterReadLock();
     try
     {
         IDataStreamHelpers.ReadByteArgsCheck(this, index);
         int i = 0;
         while (index >= 0)
         {
             var stream = streams[i++];
             if (index >= stream.Length)
             {
                 index -= stream.Length;
             }
             else
             {
                 return(stream.ReadByte(index));
             }
         }
         // unreachable code
         throw new ArgumentOutOfRangeException();
     }
     finally
     {
         streamsLock.ExitReadLock();
     }
 }
示例#2
0
        /// <inheritdoc />
        /// <remarks>Assumes nearly sequential access.</remarks>
        public byte ReadByte(long index)
        {
            IDataStreamHelpers.ReadByteArgsCheck(this, index);
            byte ret;

            lock (cacheLock)
            {
                if (!cache.TryReadByte(index, out ret))
                {
                    ByteCache.FillCache callback = delegate(byte[] buffer, out long cacheStart, out int cacheLength)
                    {
                        using (var reader = log.ReaderPool.Get())
                        {
                            // the file is more likely to be read from the beginning to the end
                            cacheStart  = Math.Max(0, index - 32);
                            cacheLength = (int)Math.Min(buffer.Length, Math.Min(int.MaxValue, length - cacheStart));
                            reader.ReadFileDataToBuffer(hint, buffer, cacheStart, cacheLength, 0);
                            ret = buffer[index - cacheStart];
                        }
                    };
                    cache.Cache(callback);
                }
            }
            return(ret);
        }
示例#3
0
 /// <inheritdoc/>
 public byte ReadByte(long index)
 {
     IDataStreamHelpers.ReadByteArgsCheck(this, index);
     lock (streamLock)
     {
         stream.Position = index;
         return((byte)stream.ReadByte());
     }
 }
示例#4
0
        /// <inheritdoc/>
        public byte ReadByte(long index)
        {
            IDataStreamHelpers.ReadByteArgsCheck(this, index);
            byte ret;

            lock (dataLock)
            {
                if (cache.TryReadByte(index, out ret))
                {
                    return(ret);
                }
                seekToPosition(index);
                cache.TryReadByte(index, out ret);
                return(ret);
            }
        }
示例#5
0
 /// <inheritdoc/>
 public byte ReadByte(long index)
 {
     IDataStreamHelpers.ReadByteArgsCheck(this, index);
     return(stream.ReadByte(offset + index));
 }
示例#6
0
 /// <inheritdoc/>
 public byte ReadByte(long index)
 {
     IDataStreamHelpers.ReadByteArgsCheck(this, index);
     return arr[index];
 }