Java Code Examples for org.apache.lucene.store.FilterDirectory#unwrap()

The following examples show how to use org.apache.lucene.store.FilterDirectory#unwrap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestUtil.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static boolean hasWindowsFS(Directory dir) {
  dir = FilterDirectory.unwrap(dir);
  if (dir instanceof FSDirectory) {
    Path path = ((FSDirectory) dir).getDirectory();
    FileSystem fs = path.getFileSystem();
    while (fs instanceof FilterFileSystem) {
      FilterFileSystem ffs = (FilterFileSystem) fs;
      if (ffs.getParent() instanceof WindowsFS) {
        return true;
      }
      fs = ffs.getDelegate();
    }
  }

  return false;
}
 
Example 2
Source File: TestUtil.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** Returns true if VirusCheckingFS is in use and was in fact already enabled */
public static boolean disableVirusChecker(Directory in) {
  Directory dir = FilterDirectory.unwrap(in);
  if (dir instanceof FSDirectory) {

    FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
    while (fs instanceof FilterFileSystem) {
      FilterFileSystem ffs = (FilterFileSystem) fs;
      if (ffs.getParent() instanceof VirusCheckingFS) {
        VirusCheckingFS vfs = (VirusCheckingFS) ffs.getParent();
        boolean isEnabled = vfs.isEnabled();
        vfs.disable();
        return isEnabled;
      }
      fs = ffs.getDelegate();
    }
  }

  return false;
}
 
Example 3
Source File: TestUtil.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static void enableVirusChecker(Directory in) {
  Directory dir = FilterDirectory.unwrap(in);
  if (dir instanceof FSDirectory) {

    FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
    while (fs instanceof FilterFileSystem) {
      FilterFileSystem ffs = (FilterFileSystem) fs;
      if (ffs.getParent() instanceof VirusCheckingFS) {
        VirusCheckingFS vfs = (VirusCheckingFS) ffs.getParent();
        vfs.enable();
        return;
      }
      fs = ffs.getDelegate();
    }
  }
}
 
Example 4
Source File: TestUtil.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static boolean hasVirusChecker(Directory dir) {
  dir = FilterDirectory.unwrap(dir);
  if (dir instanceof FSDirectory) {
    return hasVirusChecker(((FSDirectory) dir).getDirectory());
  } else {
    return false;
  }
}
 
Example 5
Source File: IOUtils.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** If the dir is an {@link FSDirectory} or wraps one via possibly
 *  nested {@link FilterDirectory} or {@link FileSwitchDirectory},
 *  this returns {@link #spins(Path)} for the wrapped directory,
 *  else, true.
 *
 *  @throws IOException if {@code path} does not exist.
 *
 *  @lucene.internal */
public static boolean spins(Directory dir) throws IOException {
  dir = FilterDirectory.unwrap(dir);
  if (dir instanceof FileSwitchDirectory) {
    FileSwitchDirectory fsd = (FileSwitchDirectory) dir;
    // Spinning is contagious:
    return spins(fsd.getPrimaryDir()) || spins(fsd.getSecondaryDir());
  } else if (dir instanceof ByteBuffersDirectory) {
    return false;
  } else if (dir instanceof FSDirectory) {
    return spins(((FSDirectory) dir).getDirectory());
  } else {
    return true;
  }
}
 
Example 6
Source File: InternalEngine.java    From crate with Apache License 2.0 5 votes vote down vote up
static Map<String, String> getReaderAttributes(Directory directory) {
    Directory unwrap = FilterDirectory.unwrap(directory);
    boolean defaultOffHeap = FsDirectoryService.isHybridFs(unwrap) || unwrap instanceof MMapDirectory;
    return Map.of(
        // if we are using MMAP for term dics we force all off heap
        BlockTreeTermsReader.FST_MODE_KEY,
        defaultOffHeap ? FSTLoadMode.OFF_HEAP.name() : FSTLoadMode.ON_HEAP.name()
    );
}
 
Example 7
Source File: FsDirectoryService.java    From crate with Apache License 2.0 4 votes vote down vote up
public static boolean isHybridFs(Directory directory) {
    Directory unwrap = FilterDirectory.unwrap(directory);
    return unwrap instanceof HybridDirectory;
}