/** * Deletes one or more files or directories (and everything underneath it). * * @throws IOException if any of the given files (or their subhierarchy files in case * of directories) cannot be removed. */ public static void rm(Path... locations) throws IOException { LinkedHashMap<Path,Throwable> unremoved = rm(new LinkedHashMap<Path,Throwable>(), locations); if (!unremoved.isEmpty()) { StringBuilder b = new StringBuilder("Could not remove the following files (in the order of attempts):\n"); for (Map.Entry<Path,Throwable> kv : unremoved.entrySet()) { b.append(" ") .append(kv.getKey().toAbsolutePath()) .append(": ") .append(kv.getValue()) .append("\n"); } throw new IOException(b.toString()); } }
@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); } }
@Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (delete) { IOUtils.rm(dir); } return CONTINUE; }
@Override public void destroy() throws IOException { IOUtils.rm(tempFile); }
@Override public void destroy() throws IOException { IOUtils.rm(tempFile); }
@Override public void destroy() throws IOException { IOUtils.rm(tempFile); }
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); }
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); }
/** * 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); } }
/** * 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); } }
/** * 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); } } } } }
/** * 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); } } } } }
/** * 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); } } } } }
static void tryToDeletePath(Terminal terminal, Path ... paths) { for (Path path : paths) { try { IOUtils.rm(path); } catch (IOException e) { terminal.printError(e); } } }
@Override public void delete(BlobPath path) throws IOException { IOUtils.rm(buildPath(path)); }
@Override public void delete(BlobPath path) throws IOException { IOUtils.rm(buildPath(path)); }
private Directory createDirectory(boolean eraseIndex, String dirName, String dirParam) throws IOException { if ("FSDirectory".equals(config.get(dirParam,"RAMDirectory"))) { 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); } return new RAMDirectory(); }
/** * Deletes an indexes data directory recursively. * Note: this method assumes that the shard lock is acquired * * @param index the index to delete * @param indexSettings settings for the index being deleted */ public void deleteIndexDirectoryUnderLock(Index index, IndexSettings indexSettings) throws IOException { final Path[] indexPaths = indexPaths(index); logger.trace("deleting index {} directory, paths({}): [{}]", index, indexPaths.length, indexPaths); IOUtils.rm(indexPaths); if (indexSettings.hasCustomDataPath()) { Path customLocation = resolveIndexCustomLocation(indexSettings); logger.trace("deleting custom index {} directory [{}]", index, customLocation); IOUtils.rm(customLocation); } }
private void clearDataIfNeeded(RestartCallback callback) throws IOException { if (callback.clearData(name)) { NodeEnvironment nodeEnv = node.getNodeEnvironment(); if (nodeEnv.hasNodeFile()) { final Path[] locations = nodeEnv.nodeDataPaths(); logger.debug("removing node data paths: [{}]", Arrays.toString(locations)); IOUtils.rm(locations); } } }
public void reset() throws Exception { try { Path[] dataPaths = nodeEnv.nodeDataPaths(); logger.trace("removing node data paths: [{}]", dataPaths); IOUtils.rm(dataPaths); } catch (Exception ex) { logger.debug("failed to delete shard locations", ex); } }