Ejemplo n.º 1
0
        /// <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();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a list of files in a give directory.
        /// </summary>
        /// <param name="fullName">The full path name to the directory.</param>
        /// <param name="indexFileNameFilter"></param>
        /// <returns>An array containing the files.</returns>
        public static System.String[] GetLuceneIndexFiles(System.String fullName,
                                                          Lucene.Net.Index.IndexFileNameFilter indexFileNameFilter)
        {
            System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(fullName);
            List <string>           list  = new List <string>();

            foreach (System.IO.FileInfo fInfo in dInfo.GetFiles())
            {
                if (indexFileNameFilter.Accept(fInfo, fInfo.Name) == true)
                {
                    list.Add(fInfo.Name);
                }
            }
            return(list.ToArray());
        }
Ejemplo n.º 3
0
 public override System.String[] List()
 {
     EnsureOpen();
     return(SupportClass.FileSupport.GetLuceneIndexFiles(directory.FullName, IndexFileNameFilter.GetFilter()));
 }
Ejemplo n.º 4
0
 private void  Create()
 {
     if (directory.Exists)
     {
         System.String[] files = SupportClass.FileSupport.GetLuceneIndexFiles(directory.FullName, IndexFileNameFilter.GetFilter());                 // clear old files
         if (files == null)
         {
             throw new System.IO.IOException("cannot read directory " + directory.FullName + ": list() returned null");
         }
         for (int i = 0; i < files.Length; i++)
         {
             System.String fileOrDir = System.IO.Path.Combine(directory.FullName, files[i]);
             if (System.IO.File.Exists(fileOrDir))
             {
                 System.IO.File.Delete(fileOrDir);
             }
             else if (System.IO.Directory.Exists(fileOrDir))
             {
                 System.IO.Directory.Delete(fileOrDir);
             }
             // no need to throw anything - if a delete fails the exc will propogate to the caller
         }
     }
     lockFactory.ClearLock(IndexWriter.WRITE_LOCK_NAME);
 }
Ejemplo n.º 5
0
 /// <summary>Returns an array of strings, one for each Lucene index file in the directory. </summary>
 public override System.String[] List()
 {
     System.String[] files = SupportClass.FileSupport.GetLuceneIndexFiles(directory.FullName, IndexFileNameFilter.GetFilter());
     for (int i = 0; i < files.Length; i++)
     {
         files[i] = System.IO.Path.GetFileName(files[i]);
     }
     return(files);
 }
Ejemplo n.º 6
0
        private void  Create()
        {
            bool tmpBool;

            if (System.IO.File.Exists(directory.FullName))
            {
                tmpBool = true;
            }
            else
            {
                tmpBool = System.IO.Directory.Exists(directory.FullName);
            }
            if (tmpBool)
            {
                System.String[] files = SupportClass.FileSupport.GetLuceneIndexFiles(directory.FullName, IndexFileNameFilter.GetFilter());
                if (files == null)
                {
                    throw new System.IO.IOException("Cannot read directory " + directory.FullName);
                }
                for (int i = 0; i < files.Length; i++)
                {
                    string file = System.IO.Path.Combine(directory.FullName, files[i]);
                    bool   tmpBool2;
                    if (System.IO.File.Exists(file))
                    {
                        System.IO.File.Delete(file);
                        tmpBool2 = true;
                    }
                    else if (System.IO.Directory.Exists(file))
                    {
                        System.IO.Directory.Delete(file);
                        tmpBool2 = true;
                    }
                    else
                    {
                        tmpBool2 = false;
                    }
                    if (!tmpBool2)
                    {
                        throw new System.IO.IOException("Cannot delete " + file);
                    }
                }
            }
            lockFactory.ClearLock(IndexWriter.WRITE_LOCK_NAME);
        }