WriteBlock() 공개 메소드

public WriteBlock ( ByteBuffer data ) : void
data ByteBuffer
리턴 void
예제 #1
0
파일: Compactor.cs 프로젝트: Xamarui/BTDB
 void MoveValuesContent(AbstractBufferedWriter writer, uint wastefullFileId)
 {
     const uint blockSize = 128 * 1024;
     var wasteFullStream = _keyValueDB.FileCollection.GetFile(wastefullFileId);
     var totalSize = wasteFullStream.GetSize();
     var blocks = (int)((totalSize + blockSize - 1) / blockSize);
     var wasteInMemory = new byte[blocks][];
     var pos = 0UL;
     for (var i = 0; i < blocks; i++)
     {
         _cancellation.ThrowIfCancellationRequested();
         wasteInMemory[i] = new byte[blockSize];
         var readSize = totalSize - pos;
         if (readSize > blockSize) readSize = blockSize;
         wasteFullStream.RandomRead(wasteInMemory[i], 0, (int)readSize, pos);
         pos += readSize;
     }
     _root.Iterate((valueFileId, valueOfs, valueSize) =>
         {
             if (valueFileId != wastefullFileId) return;
             var size = (uint)Math.Abs(valueSize);
             _newPositionMap.Add(((ulong)wastefullFileId << 32) | valueOfs, (uint)writer.GetCurrentPosition());
             pos = valueOfs;
             while (size > 0)
             {
                 _cancellation.ThrowIfCancellationRequested();
                 var blockId = pos / blockSize;
                 var blockStart = pos % blockSize;
                 var writeSize = (uint)(blockSize - blockStart);
                 if (writeSize > size) writeSize = size;
                 writer.WriteBlock(wasteInMemory[blockId], (int)blockStart, (int)writeSize);
                 size -= writeSize;
                 pos += writeSize;
             }
         });
 }