Пример #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 new EndOfStreamException("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_Renamed - BufferStart;
         BufferLength = buflen > BUFFER_SIZE ? BUFFER_SIZE : (int)buflen;
     }
 }
Пример #2
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;
     }
 }
Пример #3
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;
     }
 }
Пример #4
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;
            }
        }
Пример #5
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;
            }
        }
Пример #6
0
 private void  SwitchCurrentBuffer()
 {
     if (currentBufferIndex >= file.NumBuffers())
     {
         // end of file reached, no more buffers left
         throw new System.IO.IOException("Read past EOF");
     }
     else
     {
         currentBuffer  = file.GetBuffer(currentBufferIndex);
         bufferPosition = 0;
         bufferStart    = (long)BUFFER_SIZE * (long)currentBufferIndex;
         long buflen = length - bufferStart;
         bufferLength = buflen > BUFFER_SIZE ? BUFFER_SIZE : (int)buflen;
     }
 }
Пример #7
0
 /// <summary>Simulates a crash of OS or machine by overwriting
 /// unsynced files.
 /// </summary>
 public virtual void  Crash()
 {
     lock (this)
     {
         crashed   = true;
         openFiles = new System.Collections.Hashtable();
         System.Collections.IEnumerator it = unSyncedFiles.GetEnumerator();
         unSyncedFiles = new System.Collections.Hashtable();
         int count = 0;
         while (it.MoveNext())
         {
             System.String name = (System.String)((System.Collections.DictionaryEntry)it.Current).Value;
             RAMFile       file = (RAMFile)fileMap_ForNUnit[name];
             if (count % 3 == 0)
             {
                 DeleteFile(name, true);
             }
             else if (count % 3 == 1)
             {
                 // Zero out file entirely
                 int numBuffers = file.NumBuffers();
                 for (int i = 0; i < numBuffers; i++)
                 {
                     byte[] buffer = file.GetBuffer(i);
                     for (int j = 0; j < buffer.Length; j++)
                     {
                         buffer[j] = (byte)0;
                     }
                 }
             }
             else if (count % 3 == 2)
             {
                 // Truncate the file:
                 file.SetLength(file.GetLength() / 2);
             }
             count++;
         }
     }
 }
Пример #8
0
 /* Simulates a crash of OS or machine by overwriting
  *  unsynced files. */
 public virtual void Crash()
 {
     lock (this)
     {
         crashed          = true;
         openFiles        = new Dictionary <string, int>();
         openFilesDeleted = Support.Compatibility.SetFactory.CreateHashSet <string>();
         var it = unSyncedFiles.GetEnumerator();
         unSyncedFiles = Support.Compatibility.SetFactory.CreateHashSet <string>();
         int count = 0;
         while (it.MoveNext())
         {
             string  name = it.Current;
             RAMFile file = fileMap[name];
             if (count % 3 == 0)
             {
                 DeleteFile(name, true);
             }
             else if (count % 3 == 1)
             {
                 // Zero out file entirely
                 int numBuffers = file.NumBuffers();
                 for (int i = 0; i < numBuffers; i++)
                 {
                     byte[] buffer = file.GetBuffer(i);
                     Array.Clear(buffer, 0, buffer.Length);
                 }
             }
             else if (count % 3 == 2)
             {
                 // Truncate the file:
                 file.Length = file.Length / 2;
             }
             count++;
         }
     }
 }