Java Code Examples for org.apache.lucene.util.IOUtils#rm()
The following examples show how to use
org.apache.lucene.util.IOUtils#rm() .
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: TestCoreDiscovery.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testSolrHomeDoesntExist() throws Exception { File homeDir = solrHomeDirectory.toFile(); IOUtils.rm(homeDir.toPath()); CoreContainer cc = null; try { cc = init(); } catch (SolrException ex) { assertTrue("Core init doesn't report if solr home directory doesn't exist " + ex.getMessage(), 0 <= ex.getMessage().indexOf("solr.xml does not exist")); } finally { if (cc != null) { cc.shutdown(); } } }
Example 2
Source File: TestDirectoryReader.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testOpenReaderAfterDelete() throws IOException { Path dirFile = createTempDir("deletetest"); Directory dir = newFSDirectory(dirFile); if (dir instanceof BaseDirectoryWrapper) { ((BaseDirectoryWrapper)dir).setCheckIndexOnClose(false); // we will hit NoSuchFileException in MDW since we nuked it! } expectThrowsAnyOf(Arrays.asList(FileNotFoundException.class, NoSuchFileException.class), () -> DirectoryReader.open(dir) ); IOUtils.rm(dirFile); // Make sure we still get a CorruptIndexException (not NPE): expectThrowsAnyOf(Arrays.asList(FileNotFoundException.class, NoSuchFileException.class), () -> DirectoryReader.open(dir) ); dir.close(); }
Example 3
Source File: PerfRunData.java From lucene-solr with Apache License 2.0 | 6 votes |
private Directory createDirectory(boolean eraseIndex, String dirName, String dirParam) throws IOException { String dirImpl = config.get(dirParam, DEFAULT_DIRECTORY); if ("FSDirectory".equals(dirImpl)) { Path workDir = Paths.get(config.get("work.dir", "work")); Path indexDir = workDir.resolve(dirName); if (eraseIndex && Files.exists(indexDir)) { IOUtils.rm(indexDir); } Files.createDirectories(indexDir); return FSDirectory.open(indexDir); } if ("RAMDirectory".equals(dirImpl)) { throw new IOException("RAMDirectory has been removed, use ByteBuffersDirectory."); } if ("ByteBuffersDirectory".equals(dirImpl)) { return new ByteBuffersDirectory(); } throw new IOException("Directory type not supported: " + dirImpl); }
Example 4
Source File: HunspellStemFilterFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void inform(ResourceLoader loader) throws IOException { String dicts[] = dictionaryFiles.split(","); InputStream affix = null; List<InputStream> dictionaries = new ArrayList<>(); try { dictionaries = new ArrayList<>(); for (String file : dicts) { dictionaries.add(loader.openResource(file)); } affix = loader.openResource(affixFile); Path tempPath = Files.createTempDirectory(Dictionary.getDefaultTempDir(), "Hunspell"); try (Directory tempDir = FSDirectory.open(tempPath)) { this.dictionary = new Dictionary(tempDir, "hunspell", affix, dictionaries, ignoreCase); } finally { IOUtils.rm(tempPath); } } catch (ParseException e) { throw new IOException("Unable to load hunspell data! [dictionary=" + dictionaries + ",affix=" + affixFile + "]", e); } finally { IOUtils.closeWhileHandlingException(affix); IOUtils.closeWhileHandlingException(dictionaries); } }
Example 5
Source File: BlockDirectoryTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public static void rm(File file) { try { IOUtils.rm(file.toPath()); } catch (Throwable ignored) { // TODO: should this class care if a file couldnt be deleted? // this just emulates previous behavior, where only SecurityException would be handled. } }
Example 6
Source File: BlobIndex.java From crate with Apache License 2.0 | 5 votes |
/** * Deletes the directory for the given path. */ private void deleteIndex(Path blobRoot, String index) { if (Files.exists(blobRoot)) { logger.debug("[{}] Deleting blob index directory '{}'", index, blobRoot); try { IOUtils.rm(blobRoot); } catch (IOException e) { logger.warn("Could not delete blob index directory {}", blobRoot); } } else { logger.warn("Wanted to delete blob index directory {} but it was already gone", blobRoot); } }
Example 7
Source File: TestDirectoryReader.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testFilesOpenClose() throws IOException { // Create initial data set Path dirFile = createTempDir("TestIndexReader.testFilesOpenClose"); Directory dir = newFSDirectory(dirFile); IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))); addDoc(writer, "test"); writer.close(); dir.close(); // Try to erase the data - this ensures that the writer closed all files IOUtils.rm(dirFile); dir = newFSDirectory(dirFile); // Now create the data set again, just as before writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())) .setOpenMode(OpenMode.CREATE)); addDoc(writer, "test"); writer.close(); dir.close(); // Now open existing directory and test that reader closes all files dir = newFSDirectory(dirFile); DirectoryReader reader1 = DirectoryReader.open(dir); reader1.close(); dir.close(); // The following will fail if reader did not close // all files IOUtils.rm(dirFile); }
Example 8
Source File: TestDemo.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testDemo() throws IOException { String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm"; String text = "This is the text to be indexed. " + longTerm; Path indexPath = Files.createTempDirectory("tempIndex"); try (Directory dir = FSDirectory.open(indexPath)) { Analyzer analyzer = new StandardAnalyzer(); try (IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(analyzer))) { Document doc = new Document(); doc.add(newTextField("fieldname", text, Field.Store.YES)); iw.addDocument(doc); } // Now search the index. try (IndexReader reader = DirectoryReader.open(dir)) { IndexSearcher searcher = newSearcher(reader); assertEquals(1, searcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = searcher.search(query, 1); assertEquals(1, hits.totalHits.value); // Iterate through the results. for (int i = 0; i < hits.scoreDocs.length; i++) { Document hitDoc = searcher.doc(hits.scoreDocs[i].doc); assertEquals(text, hitDoc.get("fieldname")); } // Test simple phrase query. PhraseQuery phraseQuery = new PhraseQuery("fieldname", "to", "be"); assertEquals(1, searcher.count(phraseQuery)); } } IOUtils.rm(indexPath); }
Example 9
Source File: BaseDirectoryTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testNoDir() throws Throwable { Path tempDir = createTempDir("doesnotexist"); IOUtils.rm(tempDir); try (Directory dir = getDirectory(tempDir)) { expectThrowsAnyOf(Arrays.asList(NoSuchFileException.class, IndexNotFoundException.class), () -> { DirectoryReader.open(dir); }); } }
Example 10
Source File: BlobShard.java From crate with Apache License 2.0 | 5 votes |
void deleteShard() { Path baseDirectory = blobContainer.getBaseDirectory(); try { IOUtils.rm(baseDirectory); } catch (IOException e) { logger.warn("Could not delete blob directory: {} {}", baseDirectory, e); } }
Example 11
Source File: PerSessionDirectoryFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void cleanupSession(String sessionID) throws IOException { if (sessionID.isEmpty()) { // protect against deleting workDir entirely! throw new IllegalArgumentException("sessionID cannot be empty"); } IOUtils.rm(workDir.resolve(sessionID)); }
Example 12
Source File: PluginManager.java From Elasticsearch with Apache License 2.0 | 5 votes |
static void tryToDeletePath(Terminal terminal, Path ... paths) { for (Path path : paths) { try { IOUtils.rm(path); } catch (IOException e) { terminal.printError(e); } } }
Example 13
Source File: FileSystemUtils.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (delete) { IOUtils.rm(dir); } return CONTINUE; }
Example 14
Source File: FileSystemUtils.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Deletes all subdirectories in the given path recursively * @throws java.lang.IllegalArgumentException if the given path is not a directory */ public static void deleteSubDirectories(Path... paths) throws IOException { for (Path path : paths) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { for (Path subPath : stream) { if (Files.isDirectory(subPath)) { IOUtils.rm(subPath); } } } } }
Example 15
Source File: MetaDataStateFormat.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Deletes all meta state directories recursively for the given data locations * @param dataLocations the data location to delete */ public static void deleteMetaState(Path... dataLocations) throws IOException { Path[] stateDirectories = new Path[dataLocations.length]; for (int i = 0; i < dataLocations.length; i++) { stateDirectories[i] = dataLocations[i].resolve(STATE_DIR_NAME); } IOUtils.rm(stateDirectories); }
Example 16
Source File: ExtractWikipedia.java From lucene-solr with Apache License 2.0 | 4 votes |
public ExtractWikipedia(DocMaker docMaker, Path outputDir) throws IOException { this.outputDir = outputDir; this.docMaker = docMaker; System.out.println("Deleting all files in " + outputDir); IOUtils.rm(outputDir); }
Example 17
Source File: ExtractReuters.java From lucene-solr with Apache License 2.0 | 4 votes |
public ExtractReuters(Path reutersDir, Path outputDir) throws IOException { this.reutersDir = reutersDir; this.outputDir = outputDir; System.out.println("Deleting all files in " + outputDir); IOUtils.rm(outputDir); }
Example 18
Source File: TestLBHttpSolrClient.java From lucene-solr with Apache License 2.0 | 4 votes |
public void tearDown() throws Exception { if (jetty != null) jetty.stop(); IOUtils.rm(homeDir.toPath()); }
Example 19
Source File: TestLBHttp2SolrClient.java From lucene-solr with Apache License 2.0 | 4 votes |
public void tearDown() throws Exception { if (jetty != null) jetty.stop(); IOUtils.rm(homeDir.toPath()); }
Example 20
Source File: FsBlobStore.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public void delete(BlobPath path) throws IOException { IOUtils.rm(buildPath(path)); }