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


C# Directory.FileLength方法代码示例

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


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

示例1: DirSize

 internal static long DirSize(Directory d)
 {
     long size = 0;
     foreach (string file in d.ListAll())
     {
         size += d.FileLength(file);
     }
     return size;
 }
开发者ID:joyanta,项目名称:lucene.net,代码行数:9,代码来源:BaseCompressingDocValuesFormatTestCase.cs

示例2: BytesUsedByExtension

        private IDictionary<string, long> BytesUsedByExtension(Directory d)
        {
            IDictionary<string, long> bytesUsedByExtension = new Dictionary<string, long>();
            foreach (string file in d.ListAll())
            {
				string ext = IndexFileNames.GetExtension(file) ?? string.Empty;
                long previousLength = bytesUsedByExtension.ContainsKey(ext) ? bytesUsedByExtension[ext] : 0;
                bytesUsedByExtension[ext] = previousLength + d.FileLength(file);
            }
			foreach (string item in ExcludedExtensionsFromByteCounts()) {
				bytesUsedByExtension.Remove(item);							
			}
            return bytesUsedByExtension;
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:14,代码来源:BaseIndexFileFormatTestCase.cs

示例3: BeforeClass

        public void BeforeClass()
        {
            // NOTE: turn off compound file, this test will open some index files directly.
            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
            IndexWriterConfig config = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.KEYWORD, false)).SetUseCompoundFile(false);

            TermIndexInterval = config.TermIndexInterval;
            IndexDivisor = TestUtil.NextInt(Random(), 1, 10);
            NUMBER_OF_DOCUMENTS = AtLeast(100);
            NUMBER_OF_FIELDS = AtLeast(Math.Max(10, 3 * TermIndexInterval * IndexDivisor / NUMBER_OF_DOCUMENTS));

            Directory = NewDirectory();

            config.SetCodec(new PreFlexRWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE));
            LogMergePolicy mp = NewLogMergePolicy();
            // NOTE: turn off compound file, this test will open some index files directly.
            mp.NoCFSRatio = 0.0;
            config.SetMergePolicy(mp);

            Populate(Directory, config);

            DirectoryReader r0 = IndexReader.Open(Directory);
            SegmentReader r = LuceneTestCase.GetOnlySegmentReader(r0);
            string segment = r.SegmentName;
            r.Dispose();

            FieldInfosReader infosReader = (new PreFlexRWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE)).FieldInfosFormat().FieldInfosReader;
            FieldInfos fieldInfos = infosReader.Read(Directory, segment, "", IOContext.READONCE);
            string segmentFileName = IndexFileNames.SegmentFileName(segment, "", Lucene3xPostingsFormat.TERMS_INDEX_EXTENSION);
            long tiiFileLength = Directory.FileLength(segmentFileName);
            IndexInput input = Directory.OpenInput(segmentFileName, NewIOContext(Random()));
            TermEnum = new SegmentTermEnum(Directory.OpenInput(IndexFileNames.SegmentFileName(segment, "", Lucene3xPostingsFormat.TERMS_EXTENSION), NewIOContext(Random())), fieldInfos, false);
            int totalIndexInterval = TermEnum.IndexInterval * IndexDivisor;

            SegmentTermEnum indexEnum = new SegmentTermEnum(input, fieldInfos, true);
            Index = new TermInfosReaderIndex(indexEnum, IndexDivisor, tiiFileLength, totalIndexInterval);
            indexEnum.Dispose();
            input.Dispose();

            Reader = IndexReader.Open(Directory);
            SampleTerms = Sample(Random(), Reader, 1000);
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:42,代码来源:TestTermInfosReaderIndex.cs

示例4: TermInfosReader

        internal TermInfosReader(Directory dir, string seg, FieldInfos fis, IOContext context, int indexDivisor)
        {
            bool success = false;

            if (indexDivisor < 1 && indexDivisor != -1)
            {
                throw new System.ArgumentException("indexDivisor must be -1 (don't load terms index) or greater than 0: got " + indexDivisor);
            }

            try
            {
                Directory = dir;
                Segment = seg;
                FieldInfos = fis;

                OrigEnum = new SegmentTermEnum(Directory.OpenInput(IndexFileNames.SegmentFileName(Segment, "", Lucene3xPostingsFormat.TERMS_EXTENSION), context), FieldInfos, false);
                Size_Renamed = OrigEnum.Size;

                if (indexDivisor != -1)
                {
                    // Load terms index
                    TotalIndexInterval = OrigEnum.IndexInterval * indexDivisor;

                    string indexFileName = IndexFileNames.SegmentFileName(Segment, "", Lucene3xPostingsFormat.TERMS_INDEX_EXTENSION);
                    SegmentTermEnum indexEnum = new SegmentTermEnum(Directory.OpenInput(indexFileName, context), FieldInfos, true);

                    try
                    {
                        Index = new TermInfosReaderIndex(indexEnum, indexDivisor, dir.FileLength(indexFileName), TotalIndexInterval);
                        IndexLength = Index.Length();
                    }
                    finally
                    {
                        indexEnum.Dispose();
                    }
                }
                else
                {
                    // Do not load terms index:
                    TotalIndexInterval = -1;
                    Index = null;
                    IndexLength = -1;
                }
                success = true;
            }
            finally
            {
                // With lock-less commits, it's entirely possible (and
                // fine) to hit a FileNotFound exception above. In
                // this case, we want to explicitly close any subset
                // of things that were opened so that we don't have to
                // wait for a GC to do so.
                if (!success)
                {
                    Dispose();
                }
            }
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:58,代码来源:TermInfosReader.cs

示例5: ReadFile

 private void ReadFile(Directory dir, string name)
 {
     IndexInput input = dir.OpenInput(name, NewIOContext(Random()));
     try
     {
         long size = dir.FileLength(name);
         long bytesLeft = size;
         while (bytesLeft > 0)
         {
             int numToRead;
             if (bytesLeft < Buffer.Length)
             {
                 numToRead = (int)bytesLeft;
             }
             else
             {
                 numToRead = Buffer.Length;
             }
             input.ReadBytes(Buffer, 0, numToRead, false);
             bytesLeft -= numToRead;
         }
         // Don't do this in your real backups!  this is just
         // to force a backup to take a somewhat long time, to
         // make sure we are exercising the fact that the
         // IndexWriter should not delete this file even when I
         // take my time reading it.
         Thread.Sleep(1);
     }
     finally
     {
         input.Dispose();
     }
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:33,代码来源:TestSnapshotDeletionPolicy.cs


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