예제 #1
0
 private void SwitchCurrentBuffer()
 {
     if (CurrentBufferIndex == File.NumBuffers())
     {
         CurrentBuffer = File.AddBuffer(BUFFER_SIZE);
     }
     else
     {
         CurrentBuffer = File.GetBuffer(CurrentBufferIndex);
     }
     BufferPosition = 0;
     BufferStart    = (long)BUFFER_SIZE * (long)CurrentBufferIndex;
     BufferLength   = CurrentBuffer.Length;
 }
예제 #2
0
 private void  SwitchCurrentBuffer()
 {
     if (currentBufferIndex == file.NumBuffers())
     {
         currentBuffer = file.AddBuffer(BUFFER_SIZE);
     }
     else
     {
         currentBuffer = (byte[])file.GetBuffer(currentBufferIndex);
     }
     bufferPosition = 0;
     bufferStart    = (long)BUFFER_SIZE * (long)currentBufferIndex;
     bufferLength   = currentBuffer.Length;
 }
예제 #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  = 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
 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;
     }
 }
예제 #5
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;
     }
 }
예제 #6
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++;
         }
     }
 }
예제 #7
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++;
         }
     }
 }