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


Java FileSystemUtils.files方法代码示例

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


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

示例1: loadIndex

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
public static void loadIndex(String indexName, String indexFile, Path unzipDir, Path bwcPath, Logger logger, Path... paths) throws
    Exception {
    Path unzipDataDir = unzipDir.resolve("data");

    Path backwardsIndex = bwcPath.resolve(indexFile);
    // decompress the index
    try (InputStream stream = Files.newInputStream(backwardsIndex)) {
        TestUtil.unzip(stream, unzipDir);
    }

    // check it is unique
    assertTrue(Files.exists(unzipDataDir));
    Path[] list = FileSystemUtils.files(unzipDataDir);
    if (list.length != 1) {
        throw new IllegalStateException("Backwards index must contain exactly one cluster");
    }

    final Path src = getIndexDir(logger, indexName, indexFile, list[0]);
    copyIndex(logger, src, src.getFileName().toString(), paths);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:OldIndexUtils.java

示例2: jarHellCheck

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
/** check a candidate plugin for jar hell before installing it */
void jarHellCheck(Path candidate, Path pluginsDir) throws Exception {
    // create list of current jars in classpath
    final List<URL> jars = new ArrayList<>();
    jars.addAll(Arrays.asList(JarHell.parseClassPath()));

    // read existing bundles. this does some checks on the installation too.
    PluginsService.getPluginBundles(pluginsDir);

    // add plugin jars to the list
    Path pluginJars[] = FileSystemUtils.files(candidate, "*.jar");
    for (Path jar : pluginJars) {
        jars.add(jar.toUri().toURL());
    }
    // TODO: no jars should be an error
    // TODO: verify the classname exists in one of the jars!

    // check combined (current classpath + new jars to-be-added)
    JarHell.checkJarHell(jars.toArray(new URL[jars.size()]));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:InstallPluginCommand.java

示例3: corruptTranslogs

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
/**
 * Randomly overwrite some bytes in the translog files
 */
private void corruptTranslogs(Path directory) throws Exception {
    Path[] files = FileSystemUtils.files(directory, "translog-*");
    for (Path file : files) {
        logger.info("--> corrupting {}...", file);
        FileChannel f = FileChannel.open(file, StandardOpenOption.READ, StandardOpenOption.WRITE);
        int corruptions = scaledRandomIntBetween(10, 50);
        for (int i = 0; i < corruptions; i++) {
            // note: with the current logic, this will sometimes be a no-op
            long pos = randomIntBetween(0, (int) f.size());
            ByteBuffer junk = ByteBuffer.wrap(new byte[]{randomByte()});
            f.write(junk, pos);
        }
        f.close();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:TranslogTests.java

示例4: getNodeDir

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
private Path getNodeDir(String indexFile) throws IOException {
    Path unzipDir = createTempDir();
    Path unzipDataDir = unzipDir.resolve("data");

    // decompress the index
    Path backwardsIndex = getBwcIndicesPath().resolve(indexFile);
    try (InputStream stream = Files.newInputStream(backwardsIndex)) {
        TestUtil.unzip(stream, unzipDir);
    }

    // check it is unique
    assertTrue(Files.exists(unzipDataDir));
    Path[] list = FileSystemUtils.files(unzipDataDir);
    if (list.length != 1) {
        throw new IllegalStateException("Backwards index must contain exactly one cluster");
    }

    int zipIndex = indexFile.indexOf(".zip");
    final Version version = Version.fromString(indexFile.substring("index-".length(), zipIndex));
    if (version.before(Version.V_5_0_0_alpha1)) {
        // the bwc scripts packs the indices under this path
        return list[0].resolve("nodes/0/");
    } else {
        // after 5.0.0, data folders do not include the cluster name
        return list[0].resolve("0");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:OldIndexBackwardsCompatibilityIT.java

示例5: truncateTranslogs

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
/**
 * Randomly truncate some bytes in the translog files
 */
private void truncateTranslogs(Path directory) throws Exception {
    Path[] files = FileSystemUtils.files(directory, "translog-*");
    for (Path file : files) {
        try (FileChannel f = FileChannel.open(file, StandardOpenOption.READ, StandardOpenOption.WRITE)) {
            long prevSize = f.size();
            long newSize = prevSize - randomIntBetween(1, (int) prevSize / 2);
            logger.info("--> truncating {}, prev: {}, now: {}", file, prevSize, newSize);
            f.truncate(newSize);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:TranslogTests.java

示例6: findPluginRoot

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
/** we check whether we need to remove the top-level folder while extracting
 *  sometimes (e.g. github) the downloaded archive contains a top-level folder which needs to be removed
 */
private Path findPluginRoot(Path dir) throws IOException {
    if (Files.exists(dir.resolve(PluginInfo.ES_PLUGIN_PROPERTIES))) {
        return dir;
    } else {
        final Path[] topLevelFiles = FileSystemUtils.files(dir);
        if (topLevelFiles.length == 1 && Files.isDirectory(topLevelFiles[0])) {
            Path subdir = topLevelFiles[0];
            if (Files.exists(subdir.resolve(PluginInfo.ES_PLUGIN_PROPERTIES))) {
                return subdir;
            }
        }
    }
    throw new RuntimeException("Could not find plugin descriptor '" + PluginInfo.ES_PLUGIN_PROPERTIES + "' in plugin zip");
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:PluginManager.java

示例7: jarHellCheck

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
/** check a candidate plugin for jar hell before installing it */
private void jarHellCheck(Path candidate, boolean isolated) throws IOException {
    // create list of current jars in classpath
    final List<URL> jars = new ArrayList<>();
    jars.addAll(Arrays.asList(JarHell.parseClassPath()));

    // read existing bundles. this does some checks on the installation too.
    List<Bundle> bundles = PluginsService.getPluginBundles(environment.pluginsFile());

    // if we aren't isolated, we need to jarhellcheck against any other non-isolated plugins
    // thats always the first bundle
    if (isolated == false) {
        jars.addAll(bundles.get(0).urls);
    }

    // add plugin jars to the list
    Path pluginJars[] = FileSystemUtils.files(candidate, "*.jar");
    for (Path jar : pluginJars) {
        jars.add(jar.toUri().toURL());
    }

    // check combined (current classpath + new jars to-be-added)
    try {
        JarHell.checkJarHell(jars.toArray(new URL[jars.size()]));
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:29,代码来源:PluginManager.java

示例8: discoverJars

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
@SuppressForbidden(reason = "discover nested jar")
private void discoverJars(URI libPath, List<URL> cp, boolean optional) {
    try {
        Path[] jars = FileSystemUtils.files(PathUtils.get(libPath), "*.jar");

        for (Path path : jars) {
            cp.add(path.toUri().toURL());
        }
    } catch (IOException ex) {
        if (!optional) {
            throw new IllegalStateException("Cannot compute plugin classpath", ex);
        }
    }
}
 
开发者ID:xushjie1987,项目名称:es-hadoop-v2.2.0,代码行数:15,代码来源:HdfsPlugin.java

示例9: loadDictionary

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
/**
 * Loads the hunspell dictionary for the given local.
 *
 * @param locale       The locale of the hunspell dictionary to be loaded.
 * @param nodeSettings The node level settings
 * @param env          The node environment (from which the conf path will be resolved)
 * @return The loaded Hunspell dictionary
 * @throws Exception when loading fails (due to IO errors or malformed dictionary files)
 */
private Dictionary loadDictionary(String locale, Settings nodeSettings, Environment env) throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("Loading hunspell dictionary [{}]...", locale);
    }
    Path dicDir = hunspellDir.resolve(locale);
    if (FileSystemUtils.isAccessibleDirectory(dicDir, logger) == false) {
        throw new ElasticsearchException(String.format(Locale.ROOT, "Could not find hunspell dictionary [%s]", locale));
    }

    // merging node settings with hunspell dictionary specific settings
    Settings dictSettings = HUNSPELL_DICTIONARY_OPTIONS.get(nodeSettings);
    nodeSettings = loadDictionarySettings(dicDir, dictSettings.getByPrefix(locale + "."));

    boolean ignoreCase = nodeSettings.getAsBoolean("ignore_case", defaultIgnoreCase);

    Path[] affixFiles = FileSystemUtils.files(dicDir, "*.aff");
    if (affixFiles.length == 0) {
        throw new ElasticsearchException(String.format(Locale.ROOT, "Missing affix file for hunspell dictionary [%s]", locale));
    }
    if (affixFiles.length != 1) {
        throw new ElasticsearchException(String.format(Locale.ROOT, "Too many affix files exist for hunspell dictionary [%s]", locale));
    }
    InputStream affixStream = null;

    Path[] dicFiles = FileSystemUtils.files(dicDir, "*.dic");
    List<InputStream> dicStreams = new ArrayList<>(dicFiles.length);
    try {

        for (int i = 0; i < dicFiles.length; i++) {
            dicStreams.add(Files.newInputStream(dicFiles[i]));
        }

        affixStream = Files.newInputStream(affixFiles[0]);

        try (Directory tmp = new SimpleFSDirectory(env.tmpFile())) {
            return new Dictionary(tmp, "hunspell", affixStream, dicStreams, ignoreCase);
        }

    } catch (Exception e) {
        logger.error((Supplier<?>) () -> new ParameterizedMessage("Could not load hunspell dictionary [{}]", locale), e);
        throw e;
    } finally {
        IOUtils.close(affixStream);
        IOUtils.close(dicStreams);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:56,代码来源:HunspellService.java

示例10: listFiles

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
private Path[] listFiles() throws IOException {
    final Path[] files = FileSystemUtils.files(file);
    Arrays.sort(files);
    return files;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:FileWatcher.java

示例11: testRepositoryCreation

import org.elasticsearch.common.io.FileSystemUtils; //导入方法依赖的package包/类
public void testRepositoryCreation() throws Exception {
    Client client = client();

    Path location = randomRepoPath();

    logger.info("-->  creating repository");
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-1")
            .setType("fs").setSettings(Settings.builder()
                            .put("location", location)
            ).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));

    logger.info("--> verify the repository");
    int numberOfFiles = FileSystemUtils.files(location).length;
    VerifyRepositoryResponse verifyRepositoryResponse = client.admin().cluster().prepareVerifyRepository("test-repo-1").get();
    assertThat(verifyRepositoryResponse.getNodes().length, equalTo(cluster().numDataAndMasterNodes()));

    logger.info("--> verify that we didn't leave any files as a result of verification");
    assertThat(FileSystemUtils.files(location).length, equalTo(numberOfFiles));

    logger.info("--> check that repository is really there");
    ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().clear().setMetaData(true).get();
    MetaData metaData = clusterStateResponse.getState().getMetaData();
    RepositoriesMetaData repositoriesMetaData = metaData.custom(RepositoriesMetaData.TYPE);
    assertThat(repositoriesMetaData, notNullValue());
    assertThat(repositoriesMetaData.repository("test-repo-1"), notNullValue());
    assertThat(repositoriesMetaData.repository("test-repo-1").type(), equalTo("fs"));

    logger.info("-->  creating another repository");
    putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-2")
            .setType("fs").setSettings(Settings.builder()
                            .put("location", randomRepoPath())
            ).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));

    logger.info("--> check that both repositories are in cluster state");
    clusterStateResponse = client.admin().cluster().prepareState().clear().setMetaData(true).get();
    metaData = clusterStateResponse.getState().getMetaData();
    repositoriesMetaData = metaData.custom(RepositoriesMetaData.TYPE);
    assertThat(repositoriesMetaData, notNullValue());
    assertThat(repositoriesMetaData.repositories().size(), equalTo(2));
    assertThat(repositoriesMetaData.repository("test-repo-1"), notNullValue());
    assertThat(repositoriesMetaData.repository("test-repo-1").type(), equalTo("fs"));
    assertThat(repositoriesMetaData.repository("test-repo-2"), notNullValue());
    assertThat(repositoriesMetaData.repository("test-repo-2").type(), equalTo("fs"));

    logger.info("--> check that both repositories can be retrieved by getRepositories query");
    GetRepositoriesResponse repositoriesResponse = client.admin().cluster()
        .prepareGetRepositories(randomFrom("_all", "*", "test-repo-*")).get();
    assertThat(repositoriesResponse.repositories().size(), equalTo(2));
    assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-1"), notNullValue());
    assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-2"), notNullValue());

    logger.info("--> delete repository test-repo-1");
    client.admin().cluster().prepareDeleteRepository("test-repo-1").get();
    repositoriesResponse = client.admin().cluster().prepareGetRepositories().get();
    assertThat(repositoriesResponse.repositories().size(), equalTo(1));
    assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-2"), notNullValue());

    logger.info("--> delete repository test-repo-2");
    client.admin().cluster().prepareDeleteRepository("test-repo-2").get();
    repositoriesResponse = client.admin().cluster().prepareGetRepositories().get();
    assertThat(repositoriesResponse.repositories().size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:65,代码来源:RepositoriesIT.java


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