Beispiel #1
0
        /// <summary><inheritDoc/></summary>
        public virtual int Get(long position, byte[] bytes, int off, int len)
        {
            GroupedRandomAccessSource.SourceEntry entry = GetSourceEntryForOffset(position);
            // if true, we have run out of data to read from
            if (entry == null)
            {
                return(-1);
            }
            long offN      = entry.OffsetN(position);
            int  remaining = len;

            while (remaining > 0)
            {
                // if true, we have run out of data to read from
                if (entry == null)
                {
                    break;
                }
                if (offN > entry.source.Length())
                {
                    break;
                }
                int count = entry.source.Get(offN, bytes, off, remaining);
                if (count == -1)
                {
                    break;
                }
                off       += count;
                position  += count;
                remaining -= count;
                offN       = 0;
                entry      = GetSourceEntryForOffset(position);
            }
            return(remaining == len ? -1 : len - remaining);
        }
Beispiel #2
0
 // by default, do nothing
 /// <summary>
 /// <inheritDoc/>
 /// The source that contains the byte at position is retrieved, the correct offset into that source computed, then the value
 /// from that offset in the underlying source is returned.
 /// </summary>
 public virtual int Get(long position)
 {
     GroupedRandomAccessSource.SourceEntry entry = GetSourceEntryForOffset(position);
     // if true, we have run out of data to read from
     if (entry == null)
     {
         return(-1);
     }
     return(entry.source.Get(entry.OffsetN(position)));
 }