public int WriteBuffer(BufferManager<byte> bufferManager, FileStream targetFileStream) { var buffer = bufferManager.Dequeue(); try { int length = this.CalculateAlignedLength(buffer.UsedLength); targetFileStream.Write(buffer.Data, 0, length); return length; } finally { bufferManager.Free(buffer); } }