当前位置: 首页>>代码示例>>Java>>正文


Java IOUtils.rm方法代码示例

本文整理汇总了Java中org.apache.lucene.util.IOUtils.rm方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.rm方法的具体用法?Java IOUtils.rm怎么用?Java IOUtils.rm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.util.IOUtils的用法示例。


在下文中一共展示了IOUtils.rm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: installBin

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
/** Copies the files from {@code tmpBinDir} into {@code destBinDir}, along with permissions from dest dirs parent. */
private void installBin(PluginInfo info, Path tmpBinDir, Path destBinDir) throws Exception {
    if (Files.isDirectory(tmpBinDir) == false) {
        throw new UserException(ExitCodes.IO_ERROR, "bin in plugin " + info.getName() + " is not a directory");
    }
    Files.createDirectory(destBinDir);
    setFileAttributes(destBinDir, BIN_DIR_PERMS);

    try (DirectoryStream<Path> stream = Files.newDirectoryStream(tmpBinDir)) {
        for (Path srcFile : stream) {
            if (Files.isDirectory(srcFile)) {
                throw new UserException(
                    ExitCodes.DATA_ERROR,
                    "Directories not allowed in bin dir for plugin " + info.getName() + ", found " + srcFile.getFileName());
            }

            Path destFile = destBinDir.resolve(tmpBinDir.relativize(srcFile));
            Files.copy(srcFile, destFile);
            setFileAttributes(destFile, BIN_FILES_PERMS);
        }
    }
    IOUtils.rm(tmpBinDir); // clean up what we just copied
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:InstallPluginCommand.java

示例2: testMissingTranslog

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
public void testMissingTranslog() throws IOException {
    // test that we can force start the engine , even if the translog is missing.
    engine.close();
    // fake a new translog, causing the engine to point to a missing one.
    Translog translog = createTranslog();
    long id = translog.currentFileGeneration();
    translog.close();
    IOUtils.rm(translog.location().resolve(Translog.getFilename(id)));
    try {
        engine = createEngine(store, primaryTranslogDir);
        fail("engine shouldn't start without a valid translog id");
    } catch (EngineCreationFailureException ex) {
        // expected
    }
    // now it should be OK.
    EngineConfig config = copy(config(defaultSettings, store, primaryTranslogDir, newMergePolicy(), IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, null), EngineConfig.OpenMode.OPEN_INDEX_CREATE_TRANSLOG);
    engine = new InternalEngine(config);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:InternalEngineTests.java

示例3: clearDataIfNeeded

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
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);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:InternalTestCluster.java

示例4: deleteIndexDirectoryUnderLock

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:NodeEnvironment.java

示例5: deleteMetaState

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:MetaDataStateFormat.java

示例6: postVisitDirectory

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
    if (delete) {
        IOUtils.rm(dir);
    }
    return CONTINUE;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:FileSystemUtils.java

示例7: deleteSubDirectories

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
/**
 * 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);
                }
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:FileSystemUtils.java

示例8: installConfig

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
/**
 * Copies the files from {@code tmpConfigDir} into {@code destConfigDir}.
 * Any files existing in both the source and destination will be skipped.
 */
private void installConfig(PluginInfo info, Path tmpConfigDir, Path destConfigDir) throws Exception {
    if (Files.isDirectory(tmpConfigDir) == false) {
        throw new UserException(ExitCodes.IO_ERROR, "config in plugin " + info.getName() + " is not a directory");
    }

    Files.createDirectories(destConfigDir);
    setFileAttributes(destConfigDir, CONFIG_DIR_PERMS);
    final PosixFileAttributeView destConfigDirAttributesView =
        Files.getFileAttributeView(destConfigDir.getParent(), PosixFileAttributeView.class);
    final PosixFileAttributes destConfigDirAttributes =
        destConfigDirAttributesView != null ? destConfigDirAttributesView.readAttributes() : null;
    if (destConfigDirAttributes != null) {
        setOwnerGroup(destConfigDir, destConfigDirAttributes);
    }

    try (DirectoryStream<Path> stream = Files.newDirectoryStream(tmpConfigDir)) {
        for (Path srcFile : stream) {
            if (Files.isDirectory(srcFile)) {
                throw new UserException(ExitCodes.DATA_ERROR, "Directories not allowed in config dir for plugin " + info.getName());
            }

            Path destFile = destConfigDir.resolve(tmpConfigDir.relativize(srcFile));
            if (Files.exists(destFile) == false) {
                Files.copy(srcFile, destFile);
                setFileAttributes(destFile, CONFIG_FILES_PERMS);
                if (destConfigDirAttributes != null) {
                    setOwnerGroup(destFile, destConfigDirAttributes);
                }
            }
        }
    }
    IOUtils.rm(tmpConfigDir); // clean up what we just copied
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:InstallPluginCommand.java

示例9: tryToDeletePath

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
static void tryToDeletePath(Terminal terminal, Path ... paths) {
    for (Path path : paths) {
        try {
            IOUtils.rm(path);
        } catch (IOException e) {
            terminal.printError(e);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:PluginManager.java

示例10: afterIfSuccessful

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@Override
protected void afterIfSuccessful() throws Exception {
    super.afterIfSuccessful();

    if (translog.isOpen()) {
        if (translog.currentFileGeneration() > 1) {
            translog.commit();
            assertFileDeleted(translog, translog.currentFileGeneration() - 1);
        }
        translog.close();
    }
    assertFileIsPresent(translog, translog.currentFileGeneration());
    IOUtils.rm(translog.location()); // delete all the locations

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:TranslogTests.java

示例11: reset

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:Gateway.java

示例12: main

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    Path apiRootPath = PathUtils.get(args[0]);

    // Blow away the last execution and recreate it from scratch
    IOUtils.rm(apiRootPath);
    Files.createDirectories(apiRootPath);

    Path indexPath = apiRootPath.resolve("index.asciidoc");
    logger.info("Starting to write [index.asciidoc]");
    try (PrintStream indexStream = new PrintStream(
            Files.newOutputStream(indexPath, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE),
            false, StandardCharsets.UTF_8.name())) {
        emitGeneratedWarning(indexStream);
        List<Type> types = Definition.allSimpleTypes().stream().sorted(comparing(t -> t.name)).collect(toList());
        for (Type type : types) {
            if (type.sort.primitive) {
                // Primitives don't have methods to reference
                continue;
            }
            if ("def".equals(type.name)) {
                // def is special but doesn't have any methods all of its own.
                continue;
            }
            indexStream.print("include::");
            indexStream.print(type.struct.name);
            indexStream.println(".asciidoc[]");

            Path typePath = apiRootPath.resolve(type.struct.name + ".asciidoc");
            logger.info("Writing [{}.asciidoc]", type.name);
            try (PrintStream typeStream = new PrintStream(
                    Files.newOutputStream(typePath, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE),
                    false, StandardCharsets.UTF_8.name())) {
                emitGeneratedWarning(typeStream);
                typeStream.print("[[");
                emitAnchor(typeStream, type.struct);
                typeStream.print("]]++");
                typeStream.print(type.name);
                typeStream.println("++::");

                Consumer<Field> documentField = field -> PainlessDocGenerator.documentField(typeStream, field);
                Consumer<Method> documentMethod = method -> PainlessDocGenerator.documentMethod(typeStream, method);
                type.struct.staticMembers.values().stream().sorted(FIELD_NAME).forEach(documentField);
                type.struct.members.values().stream().sorted(FIELD_NAME).forEach(documentField);
                type.struct.staticMethods.values().stream().sorted(METHOD_NAME.thenComparing(NUMBER_OF_ARGS)).forEach(documentMethod);
                type.struct.constructors.values().stream().sorted(NUMBER_OF_ARGS).forEach(documentMethod);
                Map<String, Struct> inherited = new TreeMap<>();
                type.struct.methods.values().stream().sorted(METHOD_NAME.thenComparing(NUMBER_OF_ARGS)).forEach(method -> {
                    if (method.owner == type.struct) {
                        documentMethod(typeStream, method);
                    } else {
                        inherited.put(method.owner.name, method.owner);
                    }
                });

                if (false == inherited.isEmpty()) {
                    typeStream.print("* Inherits methods from ");
                    boolean first = true;
                    for (Struct inheritsFrom : inherited.values()) {
                        if (first) {
                            first = false;
                        } else {
                            typeStream.print(", ");
                        }
                        typeStream.print("++");
                        emitStruct(typeStream, inheritsFrom);
                        typeStream.print("++");
                    }
                    typeStream.println();
                }
            }
        }
    }
    logger.info("Done writing [index.asciidoc]");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:75,代码来源:PainlessDocGenerator.java

示例13: execute

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@Override
protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception {
    boolean batch = options.has(batchMode);

    Path translogPath = getTranslogPath(options);
    Path idxLocation = translogPath.getParent().resolve("index");

    if (Files.exists(translogPath) == false || Files.isDirectory(translogPath) == false) {
        throw new ElasticsearchException("translog directory [" + translogPath + "], must exist and be a directory");
    }

    if (Files.exists(idxLocation) == false || Files.isDirectory(idxLocation) == false) {
        throw new ElasticsearchException("unable to find a shard at [" + idxLocation + "], which must exist and be a directory");
    }

    // Hold the lock open for the duration of the tool running
    try (Directory dir = FSDirectory.open(idxLocation, NativeFSLockFactory.INSTANCE);
            Lock writeLock = dir.obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
        Set<Path> translogFiles;
        try {
            terminal.println("Checking existing translog files");
            translogFiles = filesInDirectory(translogPath);
        } catch (IOException e) {
            terminal.println("encountered IOException while listing directory, aborting...");
            throw new ElasticsearchException("failed to find existing translog files", e);
        }

        // Warn about ES being stopped and files being deleted
        warnAboutDeletingFiles(terminal, translogFiles, batch);

        List<IndexCommit> commits;
        try {
            terminal.println("Reading translog UUID information from Lucene commit from shard at [" + idxLocation + "]");
            commits = DirectoryReader.listCommits(dir);
        } catch (IndexNotFoundException infe) {
            throw new ElasticsearchException("unable to find a valid shard at [" + idxLocation + "]", infe);
        }

        // Retrieve the generation and UUID from the existing data
        Map<String, String> commitData = commits.get(commits.size() - 1).getUserData();
        String translogGeneration = commitData.get(Translog.TRANSLOG_GENERATION_KEY);
        String translogUUID = commitData.get(Translog.TRANSLOG_UUID_KEY);
        if (translogGeneration == null || translogUUID == null) {
            throw new ElasticsearchException("shard must have a valid translog generation and UUID but got: [{}] and: [{}]",
                    translogGeneration, translogUUID);
        }
        terminal.println("Translog Generation: " + translogGeneration);
        terminal.println("Translog UUID      : " + translogUUID);

        Path tempEmptyCheckpoint = translogPath.resolve("temp-" + Translog.CHECKPOINT_FILE_NAME);
        Path realEmptyCheckpoint = translogPath.resolve(Translog.CHECKPOINT_FILE_NAME);
        Path tempEmptyTranslog = translogPath.resolve("temp-" + Translog.TRANSLOG_FILE_PREFIX +
                        translogGeneration + Translog.TRANSLOG_FILE_SUFFIX);
        Path realEmptyTranslog = translogPath.resolve(Translog.TRANSLOG_FILE_PREFIX +
                        translogGeneration + Translog.TRANSLOG_FILE_SUFFIX);

        // Write empty checkpoint and translog to empty files
        long gen = Long.parseLong(translogGeneration);
        int translogLen = writeEmptyTranslog(tempEmptyTranslog, translogUUID);
        writeEmptyCheckpoint(tempEmptyCheckpoint, translogLen, gen);

        terminal.println("Removing existing translog files");
        IOUtils.rm(translogFiles.toArray(new Path[]{}));

        terminal.println("Creating new empty checkpoint at [" + realEmptyCheckpoint + "]");
        Files.move(tempEmptyCheckpoint, realEmptyCheckpoint, StandardCopyOption.ATOMIC_MOVE);
        terminal.println("Creating new empty translog at [" + realEmptyTranslog + "]");
        Files.move(tempEmptyTranslog, realEmptyTranslog, StandardCopyOption.ATOMIC_MOVE);

        // Fsync the translog directory after rename
        IOUtils.fsync(translogPath, true);

    } catch (LockObtainFailedException lofe) {
        throw new ElasticsearchException("Failed to lock shard's directory at [" + idxLocation + "], is Elasticsearch still running?");
    }

    terminal.println("Done.");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:79,代码来源:TruncateTranslogCommand.java

示例14: unzip

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
private Path unzip(Path zip, Path pluginsDir) throws IOException, UserException {
    // unzip plugin to a staging temp dir

    final Path target = stagingDirectory(pluginsDir);
    pathsToDeleteOnShutdown.add(target);

    boolean hasEsDir = false;
    try (ZipInputStream zipInput = new ZipInputStream(Files.newInputStream(zip))) {
        ZipEntry entry;
        byte[] buffer = new byte[8192];
        while ((entry = zipInput.getNextEntry()) != null) {
            if (entry.getName().startsWith("elasticsearch/") == false) {
                // only extract the elasticsearch directory
                continue;
            }
            hasEsDir = true;
            Path targetFile = target.resolve(entry.getName().substring("elasticsearch/".length()));

            // Using the entry name as a path can result in an entry outside of the plugin dir, either if the
            // name starts with the root of the filesystem, or it is a relative entry like ../whatever.
            // This check attempts to identify both cases by first normalizing the path (which removes foo/..)
            // and ensuring the normalized entry is still rooted with the target plugin directory.
            if (targetFile.normalize().startsWith(target) == false) {
                throw new IOException("Zip contains entry name '" + entry.getName() + "' resolving outside of plugin directory");
            }

            // be on the safe side: do not rely on that directories are always extracted
            // before their children (although this makes sense, but is it guaranteed?)
            if (!Files.isSymbolicLink(targetFile.getParent())) {
                Files.createDirectories(targetFile.getParent());
            }
            if (entry.isDirectory() == false) {
                try (OutputStream out = Files.newOutputStream(targetFile)) {
                    int len;
                    while ((len = zipInput.read(buffer)) >= 0) {
                        out.write(buffer, 0, len);
                    }
                }
            }
            zipInput.closeEntry();
        }
    }
    Files.delete(zip);
    if (hasEsDir == false) {
        IOUtils.rm(target);
        throw new UserException(ExitCodes.DATA_ERROR, "`elasticsearch` directory is missing in the plugin zip");
    }
    return target;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:50,代码来源:InstallPluginCommand.java

示例15: install

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
/**
 * Installs the plugin from {@code tmpRoot} into the plugins dir.
 * If the plugin has a bin dir and/or a config dir, those are copied.
 */
private void install(Terminal terminal, boolean isBatch, Path tmpRoot, Environment env) throws Exception {
    List<Path> deleteOnFailure = new ArrayList<>();
    deleteOnFailure.add(tmpRoot);

    try {
        PluginInfo info = verify(terminal, tmpRoot, isBatch, env);
        final Path destination = env.pluginsFile().resolve(info.getName());

        Path tmpBinDir = tmpRoot.resolve("bin");
        if (Files.exists(tmpBinDir)) {
            Path destBinDir = env.binFile().resolve(info.getName());
            deleteOnFailure.add(destBinDir);
            installBin(info, tmpBinDir, destBinDir);
        }

        Path tmpConfigDir = tmpRoot.resolve("config");
        if (Files.exists(tmpConfigDir)) {
            // some files may already exist, and we don't remove plugin config files on plugin removal,
            // so any installed config files are left on failure too
            installConfig(info, tmpConfigDir, env.configFile().resolve(info.getName()));
        }

        Files.move(tmpRoot, destination, StandardCopyOption.ATOMIC_MOVE);
        Files.walkFileTree(destination, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path pluginFile, BasicFileAttributes attrs) throws IOException {
                if (Files.isDirectory(pluginFile)) {
                    setFileAttributes(pluginFile, PLUGIN_DIR_PERMS);
                } else {
                    // There can also be "bin" directories under the plugin directory, storing native code executables
                    Path parentDir = pluginFile.getParent().getFileName();
                    if ("bin".equals(parentDir.toString())) {
                        setFileAttributes(pluginFile, BIN_FILES_PERMS);
                    } else {
                        setFileAttributes(pluginFile, PLUGIN_FILES_PERMS);
                    }
                }
                return FileVisitResult.CONTINUE;
            }
        });

        terminal.println("-> Installed " + info.getName());

    } catch (Exception installProblem) {
        try {
            IOUtils.rm(deleteOnFailure.toArray(new Path[0]));
        } catch (IOException exceptionWhileRemovingFiles) {
            installProblem.addSuppressed(exceptionWhileRemovingFiles);
        }
        throw installProblem;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:57,代码来源:InstallPluginCommand.java


注:本文中的org.apache.lucene.util.IOUtils.rm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。