Example #1
0
 private void SwitchCurrentBuffer(bool enforceEOF)
 {
     bufferStart = (long)BUFFER_SIZE * (long)currentBufferIndex;
     if (currentBufferIndex >= file.NumBuffers)
     {
         // end of file reached, no more buffers left
         if (enforceEOF)
         {
             throw EOFException.Create("read past EOF: " + this);
         }
         else
         {
             // Force EOF if a read takes place at this position
             currentBufferIndex--;
             bufferPosition = BUFFER_SIZE;
         }
     }
     else
     {
         currentBuffer  = file.GetBuffer(currentBufferIndex);
         bufferPosition = 0;
         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(DataOutput @out)
        {
            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.WriteBytes(file.GetBuffer(buffer++), length);
                pos = nextPos;
            }
        }