internal ReliableRAMOutputStream(ReliableRAMFile f)
        {
            file = f;

            // make sure that we switch to the
            // first needed buffer lazily
            currentBufferIndex = - 1;
            currentBuffer = null;
        }
 public static void UpdateFile(ReliableRAMFile file)
 {
     var existing = GetFile(file.MapName);
     using (var tx = StateManager.CreateTransaction())
     {
         fileMap.TryUpdateAsync(tx, file.MapName, file, existing);
         tx.CommitAsync().GetAwaiter().GetResult();
     }
 }
        /*internal*/
        public ReliableRAMInputStream(ReliableRAMFile f)
        {
            file = f;
            length = file.length;
            if (length / BUFFER_SIZE >= System.Int32.MaxValue)
            {
                throw new System.IO.IOException("Too large RAMFile! " + length);
            }

            // make sure that we switch to the
            // first needed buffer lazily
            currentBufferIndex = - 1;
            currentBuffer = null;
        }
		/// <summary>Creates a new, empty file in the directory with the given name. Returns a stream writing this file. </summary>
		public override IndexOutput CreateOutput(System.String name)
		{
			EnsureOpen();
            ReliableRAMFile file = new ReliableRAMFile(this, name);
            ReliableRAMFile existing = GetFile(name);
            using (var tx = StateManager.CreateTransaction())
            {
                if (existing != null)
                {
                    internalSizeInBytes -= existing.sizeInBytes;
                    existing.directory = null;
                    fileMap.TryUpdateAsync(tx, name, file, existing).GetAwaiter().GetResult();
                }
                else
                {
                    fileMap.TryAddAsync(tx, name, file).GetAwaiter().GetResult();
                }
                tx.CommitAsync().GetAwaiter().GetResult();
            }
            return new ReliableRAMOutputStream(file);
		}