当前位置: 首页>>代码示例>>C#>>正文


C# Directory.CreateOutput方法代码示例

本文整理汇总了C#中Lucene.Net.Store.Directory.CreateOutput方法的典型用法代码示例。如果您正苦于以下问题:C# Directory.CreateOutput方法的具体用法?C# Directory.CreateOutput怎么用?C# Directory.CreateOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Store.Directory的用法示例。


在下文中一共展示了Directory.CreateOutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateSequenceFile

 /// <summary>
 /// Creates a file of the specified size with sequential data. The first
 ///  byte is written as the start byte provided. All subsequent bytes are
 ///  computed as start + offset where offset is the number of the byte.
 /// </summary>
 private void CreateSequenceFile(Directory dir, string name, sbyte start, int size)
 {
     IndexOutput os = dir.CreateOutput(name, NewIOContext(Random()));
     for (int i = 0; i < size; i++)
     {
         os.WriteByte((byte)start);
         start++;
     }
     os.Dispose();
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:15,代码来源:TestCompoundFile.cs

示例2: CreateRandomFile

 /// <summary>
 /// Creates a file of the specified size with random data. </summary>
 private void CreateRandomFile(Directory dir, string name, int size)
 {
     IndexOutput os = dir.CreateOutput(name, NewIOContext(Random()));
     for (int i = 0; i < size; i++)
     {
         var b = unchecked((sbyte)(new Random(1).NextDouble() * 256));
         os.WriteByte((byte)b);
     }
     os.Dispose();
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:12,代码来源:TestCompoundFile.cs

示例3: UnidirectionalSync

        private static void UnidirectionalSync(AzureDirectory sourceDirectory, Directory destinationDirectory)
        {
            var sourceFiles = sourceDirectory.ListAll();

            var fileNameFilter = IndexFileNameFilter.Filter;
            byte[] buffer = new byte[16384];

            foreach (string sourceFile in sourceFiles)
            {
                // only copy file if it is accepted by Lucene's default filter
                // and it does not already exist (except for segment map files, we always want those)
                if (fileNameFilter.Accept(null, sourceFile) && (!destinationDirectory.FileExists(sourceFile) || sourceFile.StartsWith("segment")))
                {
                    IndexOutput indexOutput = null;
                    IndexInput indexInput = null;
                    try
                    {
                        indexOutput = destinationDirectory.CreateOutput(sourceFile);
                        indexInput = sourceDirectory.OpenInput(sourceFile);

                        long length = indexInput.Length();
                        long position = 0;
                        while (position < length)
                        {
                            int bytesToRead = position + 16384L > length ? (int)(length - position) : 16384;
                            indexInput.ReadBytes(buffer, 0, bytesToRead);
                            indexOutput.WriteBytes(buffer, bytesToRead);

                            position += bytesToRead;
                        }
                    }
                    finally
                    {
                        try
                        {
                            indexOutput?.Close();
                        }
                        finally
                        {
                            indexInput?.Close();
                        }
                    }
                }
            }

            // we'll remove old files from both AzureDirectory's cache directory, as well as our destination directory
            // (only when older than 45 minutes - old files may still have active searches on them so we need a margin)
            var referenceTimestamp = LuceneTimestampFromDateTime(DateTime.UtcNow.AddMinutes(-45));

            // remove old files from AzureDirectory cache directory
            RemoveOldFiles(sourceDirectory.CacheDirectory, sourceFiles, referenceTimestamp);

            // remove old files from destination directory
            RemoveOldFiles(destinationDirectory, sourceFiles, referenceTimestamp);
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:55,代码来源:AzureDirectorySynchronizer.cs

示例4: MockSingleIntIndexOutput

 public MockSingleIntIndexOutput(Directory dir, string fileName, IOContext context)
 {
     @out = dir.CreateOutput(fileName, context);
     bool success = false;
     try
     {
         CodecUtil.WriteHeader(@out, CODEC, VERSION_CURRENT);
         success = true;
     }
     finally
     {
         if (!success)
         {
             IOUtils.CloseWhileHandlingException(@out);
         }
     }
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:17,代码来源:MockSingleIntIndexOutput.cs

示例5: SecureStoreIndexOutput

        public SecureStoreIndexOutput(Directory cache, string cachePath, Func<DataWithMetadata, Task> saveTask)
        {
            _cache = cache;
            _name = cachePath;
            _saveTask = saveTask;

            _fileMutex = BlobMutexManager.GrabMutex(_name);
            _fileMutex.WaitOne();
            try
            {
                // create the local cache one we will operate against...
                _indexOutput = _cache.CreateOutput(_name);
            }
            finally
            {
                _fileMutex.ReleaseMutex();
            }
        }
开发者ID:KalixHealth,项目名称:Kalix.Leo,代码行数:18,代码来源:SecureStoreIndexOutput.cs

示例6: Copy

		/// <summary> Copy contents of a directory src to a directory dest.
		/// If a file in src already exists in dest then the
		/// one in dest will be blindly overwritten.
		/// 
		/// <p/><b>NOTE:</b> the source directory cannot change
		/// while this method is running.  Otherwise the results
		/// are undefined and you could easily hit a
		/// FileNotFoundException.
		/// 
		/// <p/><b>NOTE:</b> this method only copies files that look
		/// like index files (ie, have extensions matching the
		/// known extensions of index files).
		/// 
		/// </summary>
		/// <param name="src">source directory
		/// </param>
		/// <param name="dest">destination directory
		/// </param>
		/// <param name="closeDirSrc">if <code>true</code>, call {@link #Close()} method on source directory
		/// </param>
		/// <throws>  IOException </throws>
		public static void  Copy(Directory src, Directory dest, bool closeDirSrc)
		{
			System.String[] files = src.ListAll();
			
			IndexFileNameFilter filter = IndexFileNameFilter.GetFilter();
			
			byte[] buf = new byte[BufferedIndexOutput.BUFFER_SIZE];
			for (int i = 0; i < files.Length; i++)
			{
				
				if (!filter.Accept(null, files[i]))
					continue;
				
				IndexOutput os = null;
				IndexInput is_Renamed = null;
				try
				{
					// create file in dest directory
					os = dest.CreateOutput(files[i]);
					// read current file
					is_Renamed = src.OpenInput(files[i]);
					// and copy to dest directory
					long len = is_Renamed.Length();
					long readCount = 0;
					while (readCount < len)
					{
						int toRead = readCount + BufferedIndexOutput.BUFFER_SIZE > len?(int) (len - readCount):BufferedIndexOutput.BUFFER_SIZE;
						is_Renamed.ReadBytes(buf, 0, toRead);
						os.WriteBytes(buf, toRead);
						readCount += toRead;
					}
				}
				finally
				{
					// graceful cleanup
					try
					{
						if (os != null)
							os.Close();
					}
					finally
					{
						if (is_Renamed != null)
							is_Renamed.Close();
					}
				}
			}
			if (closeDirSrc)
				src.Close();
		}
开发者ID:Inzaghi2012,项目名称:teamlab.v7.5,代码行数:71,代码来源:Directory.cs

示例7: CheckDirectoryFilter

		// LUCENE-1468
		private void  CheckDirectoryFilter(Directory dir)
		{
			System.String name = "file";
			try
			{
				dir.CreateOutput(name).Close();
				Assert.IsTrue(dir.FileExists(name));
				Assert.IsTrue(new System.Collections.ArrayList(dir.ListAll()).Contains(name));
			}
			finally
			{
				dir.Close();
			}
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:15,代码来源:TestDirectory.cs

示例8: CompressingStoredFieldsWriter

        private int NumBufferedDocs; // docBase + numBufferedDocs == current doc ID

        /// <summary>
        /// Sole constructor. </summary>
        public CompressingStoredFieldsWriter(Directory directory, SegmentInfo si, string segmentSuffix, IOContext context, string formatName, CompressionMode compressionMode, int chunkSize)
        {
            Debug.Assert(directory != null);
            this.Directory = directory;
            this.Segment = si.Name;
            this.SegmentSuffix = segmentSuffix;
            this.CompressionMode = compressionMode;
            this.Compressor = compressionMode.NewCompressor();
            this.ChunkSize = chunkSize;
            this.DocBase = 0;
            this.BufferedDocs = new GrowableByteArrayDataOutput(chunkSize);
            this.NumStoredFields = new int[16];
            this.EndOffsets = new int[16];
            this.NumBufferedDocs = 0;

            bool success = false;
            IndexOutput indexStream = directory.CreateOutput(IndexFileNames.SegmentFileName(Segment, segmentSuffix, Lucene40StoredFieldsWriter.FIELDS_INDEX_EXTENSION), context);
            try
            {
                FieldsStream = directory.CreateOutput(IndexFileNames.SegmentFileName(Segment, segmentSuffix, Lucene40StoredFieldsWriter.FIELDS_EXTENSION), context);

                string codecNameIdx = formatName + CODEC_SFX_IDX;
                string codecNameDat = formatName + CODEC_SFX_DAT;
                CodecUtil.WriteHeader(indexStream, codecNameIdx, VERSION_CURRENT);
                CodecUtil.WriteHeader(FieldsStream, codecNameDat, VERSION_CURRENT);
                Debug.Assert(CodecUtil.HeaderLength(codecNameDat) == FieldsStream.FilePointer);
                Debug.Assert(CodecUtil.HeaderLength(codecNameIdx) == indexStream.FilePointer);

                IndexWriter = new CompressingStoredFieldsIndexWriter(indexStream);
                indexStream = null;

                FieldsStream.WriteVInt(chunkSize);
                FieldsStream.WriteVInt(PackedInts.VERSION_CURRENT);

                success = true;
            }
            finally
            {
                if (!success)
                {
                    IOUtils.CloseWhileHandlingException(indexStream);
                    Abort();
                }
            }
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:49,代码来源:CompressingStoredFieldsWriter.cs

示例9: CheckDirectoryFilter

 // LUCENE-1468
 private void CheckDirectoryFilter(Directory dir)
 {
     string name = "file";
     try
     {
         dir.CreateOutput(name, NewIOContext(Random())).Dispose();
         Assert.IsTrue(SlowFileExists(dir, name));
         Assert.IsTrue(Arrays.AsList(dir.ListAll()).Contains(name));
     }
     finally
     {
         dir.Dispose();
     }
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:15,代码来源:TestDirectory.cs

示例10: Copy

        /// <summary> Copy contents of a directory src to a directory dest.
        /// If a file in src already exists in dest then the
        /// one in dest will be blindly overwritten.
        /// 
        /// </summary>
        /// <param name="src">source directory
        /// </param>
        /// <param name="dest">destination directory
        /// </param>
        /// <param name="closeDirSrc">if <code>true</code>, call {@link #close()} method on source directory
        /// </param>
        /// <throws>  IOException </throws>
        public static void Copy(Directory src, Directory dest, bool closeDirSrc)
        {
            System.String[] files = src.List();

            if (files == null)
            {
                throw new System.IO.IOException("cannot read directory " + src + ": list() returned null");
            }

            byte[] buf = new byte[BufferedIndexOutput.BUFFER_SIZE];
            for (int i = 0; i < files.Length; i++)
            {
                IndexOutput os = null;
                IndexInput is_Renamed = null;
                try
                {
                    // create file in dest directory
                    os = dest.CreateOutput(files[i]);
                    // read current file
                    is_Renamed = src.OpenInput(files[i]);
                    // and copy to dest directory
                    long len = is_Renamed.Length();
                    long readCount = 0;
                    while (readCount < len)
                    {
                        int toRead = readCount + BufferedIndexOutput.BUFFER_SIZE > len ? (int) (len - readCount) : BufferedIndexOutput.BUFFER_SIZE;
                        is_Renamed.ReadBytes(buf, 0, toRead);
                        os.WriteBytes(buf, toRead);
                        readCount += toRead;
                    }
                }
                finally
                {
                    // graceful cleanup
                    try
                    {
                        if (os != null)
                            os.Close();
                    }
                    finally
                    {
                        if (is_Renamed != null)
                            is_Renamed.Close();
                    }
                }
            }
            if (closeDirSrc)
                src.Close();
        }
开发者ID:cqm0609,项目名称:lucene-file-finder,代码行数:61,代码来源:Directory.cs

示例11: CreateOutput

 public override IntIndexOutput CreateOutput(Directory dir, string fileName, IOContext context)
 {
     IndexOutput output = dir.CreateOutput(fileName, context);
     bool success = false;
     try
     {
         output.WriteInt(baseBlockSize);
         VariableIntBlockIndexOutput ret = new VariableIntBlockIndexOutputAnonymousHelper(output, 2 * baseBlockSize);
         success = true;
         return ret;
     }
     finally
     {
         if (!success)
         {
             IOUtils.CloseWhileHandlingException(output);
         }
     }
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:19,代码来源:MockVariableIntBlockPostingsFormat.cs

示例12: Write3xInfo

        public static string Write3xInfo(Directory dir, SegmentInfo si, IOContext context)
        {
            // NOTE: this is NOT how 3.x is really written...
            string fileName = IndexFileNames.SegmentFileName(si.Name, "", Lucene3xSegmentInfoFormat.UPGRADED_SI_EXTENSION);
            si.AddFile(fileName);

            //System.out.println("UPGRADE write " + fileName);
            bool success = false;
            IndexOutput output = dir.CreateOutput(fileName, context);
            try
            {
                // we are about to write this SI in 3.x format, dropping all codec information, etc.
                // so it had better be a 3.x segment or you will get very confusing errors later.
                if ((si.Codec is Lucene3xCodec) == false)
                {
                    throw new InvalidOperationException("cannot write 3x SegmentInfo unless codec is Lucene3x (got: " + si.Codec + ")");
                }

                CodecUtil.WriteHeader(output, Lucene3xSegmentInfoFormat.UPGRADED_SI_CODEC_NAME, Lucene3xSegmentInfoFormat.UPGRADED_SI_VERSION_CURRENT);
                // Write the Lucene version that created this segment, since 3.1
                output.WriteString(si.Version);
                output.WriteInt(si.DocCount);

                output.WriteStringStringMap(si.Attributes());

                output.WriteByte((byte)(sbyte)(si.UseCompoundFile ? SegmentInfo.YES : SegmentInfo.NO));
                output.WriteStringStringMap(si.Diagnostics);
                output.WriteStringSet(si.Files);

                output.Dispose();

                success = true;
            }
            finally
            {
                if (!success)
                {
                    IOUtils.CloseWhileHandlingException(output);
                    try
                    {
                        si.Dir.DeleteFile(fileName);
                    }
                    catch (Exception)
                    {
                        // Suppress so we keep throwing the original exception
                    }
                }
            }

            return fileName;
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:51,代码来源:SegmentInfos.cs

示例13: Write

        private void Write(Directory directory)
        {
            string segmentsFileName = NextSegmentFileName;

            // Always advance the generation on write:
            if (_generation == -1)
            {
                _generation = 1;
            }
            else
            {
                _generation++;
            }

            IndexOutput segnOutput = null;
            bool success = false;

            var upgradedSIFiles = new HashSet<string>();

            try
            {
                segnOutput = directory.CreateOutput(segmentsFileName, IOContext.DEFAULT);
                CodecUtil.WriteHeader(segnOutput, "segments", VERSION_48);
                segnOutput.WriteLong(Version);
                segnOutput.WriteInt(Counter); // write counter
                segnOutput.WriteInt(Size()); // write infos
                foreach (SegmentCommitInfo siPerCommit in segments)
                {
                    SegmentInfo si = siPerCommit.Info;
                    segnOutput.WriteString(si.Name);
                    segnOutput.WriteString(si.Codec.Name);
                    segnOutput.WriteLong(siPerCommit.DelGen);
                    int delCount = siPerCommit.DelCount;
                    if (delCount < 0 || delCount > si.DocCount)
                    {
                        throw new InvalidOperationException("cannot write segment: invalid docCount segment=" + si.Name + " docCount=" + si.DocCount + " delCount=" + delCount);
                    }
                    segnOutput.WriteInt(delCount);
                    segnOutput.WriteLong(siPerCommit.FieldInfosGen);
                    IDictionary<long, ISet<string>> genUpdatesFiles = siPerCommit.UpdatesFiles;
                    segnOutput.WriteInt(genUpdatesFiles.Count);
                    foreach (KeyValuePair<long, ISet<string>> e in genUpdatesFiles)
                    {
                        segnOutput.WriteLong(e.Key);
                        segnOutput.WriteStringSet(e.Value);
                    }
                    Debug.Assert(si.Dir == directory);

                    // If this segment is pre-4.x, perform a one-time
                    // "ugprade" to write the .si file for it:
                    string version = si.Version;
                    if (version == null || StringHelper.VersionComparator.Compare(version, "4.0") < 0)
                    {
                        if (!SegmentWasUpgraded(directory, si))
                        {
                            string markerFileName = IndexFileNames.SegmentFileName(si.Name, "upgraded", Lucene3xSegmentInfoFormat.UPGRADED_SI_EXTENSION);
                            si.AddFile(markerFileName);

                            string segmentFileName = Write3xInfo(directory, si, IOContext.DEFAULT);
                            upgradedSIFiles.Add(segmentFileName);
                            directory.Sync(/*Collections.singletonList(*/new[] { segmentFileName }/*)*/);

                            // Write separate marker file indicating upgrade
                            // is completed.  this way, if there is a JVM
                            // kill/crash, OS crash, power loss, etc. while
                            // writing the upgraded file, the marker file
                            // will be missing:
                            IndexOutput @out = directory.CreateOutput(markerFileName, IOContext.DEFAULT);
                            try
                            {
                                CodecUtil.WriteHeader(@out, SEGMENT_INFO_UPGRADE_CODEC, SEGMENT_INFO_UPGRADE_VERSION);
                            }
                            finally
                            {
                                @out.Dispose();
                            }
                            upgradedSIFiles.Add(markerFileName);
                            directory.Sync(/*Collections.SingletonList(*/new[] { markerFileName }/*)*/);
                        }
                    }
                }
                segnOutput.WriteStringStringMap(_userData);
                PendingSegnOutput = segnOutput;
                success = true;
            }
            finally
            {
                if (!success)
                {
                    // We hit an exception above; try to close the file
                    // but suppress any exception:
                    IOUtils.CloseWhileHandlingException(segnOutput);

                    foreach (string fileName in upgradedSIFiles)
                    {
                        try
                        {
                            directory.DeleteFile(fileName);
                        }
                        catch (Exception)
//.........这里部分代码省略.........
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:101,代码来源:SegmentInfos.cs

示例14: WriteSegmentsGen

 /// <summary>
 /// A utility for writing the <seealso cref="IndexFileNames#SEGMENTS_GEN"/> file to a
 /// <seealso cref="Directory"/>.
 ///
 /// <p>
 /// <b>NOTE:</b> this is an internal utility which is kept public so that it's
 /// accessible by code from other packages. You should avoid calling this
 /// method unless you're absolutely sure what you're doing!
 ///
 /// @lucene.internal
 /// </summary>
 public static void WriteSegmentsGen(Directory dir, long generation)
 {
     try
     {
         IndexOutput genOutput = dir.CreateOutput(IndexFileNames.SEGMENTS_GEN, IOContext.READONCE);
         try
         {
             genOutput.WriteInt(FORMAT_SEGMENTS_GEN_CURRENT);
             genOutput.WriteLong(generation);
             genOutput.WriteLong(generation);
             CodecUtil.WriteFooter(genOutput);
         }
         finally
         {
             genOutput.Dispose();
             dir.Sync(Collections.Singleton(IndexFileNames.SEGMENTS_GEN));
         }
     }
     catch (Exception)
     {
         // It's OK if we fail to write this file since it's
         // used only as one of the retry fallbacks.
         try
         {
             dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
         }
         catch (Exception)
         {
             // Ignore; this file is only used in a retry
             // fallback on init.
         }
     }
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:44,代码来源:SegmentInfos.cs

示例15: WriteIndexVersion

 private void WriteIndexVersion(LuceneDirectory directory)
 {
     using (var indexOutput = directory.CreateOutput(IndexVersionFilename))
     {
         indexOutput.WriteString(IndexVersion);
         indexOutput.Flush();
     }
 }
开发者ID:j2jensen,项目名称:ravendb,代码行数:8,代码来源:IndexStorage.cs


注:本文中的Lucene.Net.Store.Directory.CreateOutput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。