private RAMDirectory(FSDirectory dir, boolean closeDir, IOContext context) throws IOException {
   this();
   for (String file : dir.listAll()) {
     if (!Files.isDirectory(dir.getDirectory().resolve(file))) {
       copyFrom(dir, file, file, context);
     }
   }
   if (closeDir) {
     dir.close();
   }
 }
  @PostConstruct
  private void init() {

    luceneDirectory = propertyHandler.getLuceneDirectory();
    active = luceneDirectory != null;
    if (active) {
      luceneRefreshSeconds = propertyHandler.getLuceneRefreshSeconds() * 1000L;
      luceneCommitCount = propertyHandler.getLuceneCommitCount();
      ei = EntityInfoHandler.getInstance();

      try {
        directory = FSDirectory.open(new File(luceneDirectory));
        logger.debug("Opened FSDirectory with lockid " + directory.getLockID());
        Analyzer analyzer = new IcatAnalyzer(Version.LUCENE_43);
        IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, analyzer);
        iwriter = new IndexWriter(directory, config);
        String[] files = directory.listAll();
        if (files.length == 1 && files[0].equals("write.lock")) {
          logger.debug("Directory only has the write.lock file so commit and reopen");
          iwriter.commit();
          iwriter.close();
          iwriter = new IndexWriter(directory, config);
        }

        searcherManager = new SearcherManager(directory, new SearcherFactory());
        isearcher = searcherManager.acquire();
        logger.debug("Got a new IndexSearcher " + isearcher);

        parser = new StandardQueryParser();
        StandardQueryConfigHandler qpConf =
            (StandardQueryConfigHandler) parser.getQueryConfigHandler();
        qpConf.set(ConfigurationKeys.ANALYZER, analyzer);
        qpConf.set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, true);
      } catch (Exception e) {
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        logger.fatal(errors.toString());
        if (directory != null) {
          try {
            String lockId = directory.getLockID();
            directory.clearLock(lockId);
            logger.warn("Cleared lock " + lockId);
          } catch (IOException e1) {
            // Ignore
          }
        }
        throw new IllegalStateException(errors.toString());
      }

      timer = new Timer("Lucene");
      timer.schedule(
          new TimerTask() {

            @Override
            public void run() {
              try {
                commit();
              } catch (IcatException e) {
                logger.error(e.getMessage());
              } catch (Throwable t) {
                logger.error(t.getMessage());
              }
            }
          },
          luceneRefreshSeconds,
          luceneRefreshSeconds);

      logger.debug("Created LuceneSingleton");
    }
  }