Example #1
0
 private void  SwitchCurrentBuffer(bool enforceEOF)
 {
     if (currentBufferIndex >= file.NumBuffers())
     {
         // end of file reached, no more buffers left
         if (enforceEOF)
         {
             throw new System.IO.IOException("Read past EOF");
         }
         else
         {
             // Force EOF if a read takes place at this position
             currentBufferIndex--;
             bufferPosition = BUFFER_SIZE;
         }
     }
     else
     {
         currentBuffer  = (byte[])file.GetBuffer(currentBufferIndex);
         bufferPosition = 0;
         bufferStart    = (long)BUFFER_SIZE * (long)currentBufferIndex;
         long buflen = length - bufferStart;
         bufferLength = buflen > BUFFER_SIZE?BUFFER_SIZE:(int)buflen;
     }
 }
Example #2
0
        /// <summary>Copy the current contents of this buffer to the named output. </summary>
        public virtual void  WriteTo(IndexOutput out_Renamed)
        {
            Flush();
            long end    = file.length;
            long pos    = 0;
            int  buffer = 0;

            while (pos < end)
            {
                int  length  = BUFFER_SIZE;
                long nextPos = pos + length;
                if (nextPos > end)
                {
                    // at the last buffer
                    length = (int)(end - pos);
                }
                out_Renamed.WriteBytes((byte[])file.GetBuffer(buffer++), length);
                pos = nextPos;
            }
        }