• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FileSystemUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



FileSystemUtils类属于org.elasticsearch.common.io包,在下文中一共展示了FileSystemUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: getFileSystem

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
/**
 * Returns a new FileSystem to read REST resources, or null if they
 * are available from classpath.
 */
@SuppressForbidden(reason = "proper use of URL, hack around a JDK bug")
protected static FileSystem getFileSystem() throws IOException {
    // REST suite handling is currently complicated, with lots of filtering and so on
    // For now, to work embedded in a jar, return a ZipFileSystem over the jar contents.
    URL codeLocation = FileUtils.class.getProtectionDomain().getCodeSource().getLocation();
    boolean loadPackaged = RandomizedTest.systemPropertyAsBoolean(REST_LOAD_PACKAGED_TESTS, true);
    if (codeLocation.getFile().endsWith(".jar") && loadPackaged) {
        try {
            // hack around a bug in the zipfilesystem implementation before java 9,
            // its checkWritable was incorrect and it won't work without write permissions.
            // if we add the permission, it will open jars r/w, which is too scary! so copy to a safe r-w location.
            Path tmp = Files.createTempFile(null, ".jar");
            try (InputStream in = FileSystemUtils.openFileURLStream(codeLocation)) {
                Files.copy(in, tmp, StandardCopyOption.REPLACE_EXISTING);
            }
            return FileSystems.newFileSystem(new URI("jar:" + tmp.toUri()), Collections.emptyMap());
        } catch (URISyntaxException e) {
            throw new IOException("couldn't open zipfilesystem: ", e);
        }
    } else {
        return null;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:ESClientYamlSuiteTestCase.java


示例3: 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


示例4: getModuleBundles

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
static List<Bundle> getModuleBundles(Path modulesDirectory) throws IOException {
    // damn leniency
    if (Files.notExists(modulesDirectory)) {
        return Collections.emptyList();
    }
    List<Bundle> bundles = new ArrayList<>();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(modulesDirectory)) {
        for (Path module : stream) {
            if (FileSystemUtils.isHidden(module)) {
                continue; // skip over .DS_Store etc
            }
            PluginInfo info = PluginInfo.readFromProperties(module);
            Bundle bundle = new Bundle();
            bundle.plugins.add(info);
            // gather urls for jar files
            try (DirectoryStream<Path> jarStream = Files.newDirectoryStream(module, "*.jar")) {
                for (Path jar : jarStream) {
                    // normalize with toRealPath to get symlinks out of our hair
                    bundle.urls.add(jar.toRealPath().toUri().toURL());
                }
            }
            bundles.add(bundle);
        }
    }
    return bundles;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:PluginsService.java


示例5: 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


示例6: canDeleteShardContent

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
private boolean canDeleteShardContent(ShardId shardId, Settings indexSettings) {
    final IndexServiceInjectorPair indexServiceInjectorPair = this.indices.get(shardId.getIndex());
    if (IndexMetaData.isOnSharedFilesystem(indexSettings) == false) {
         if (nodeEnv.hasNodeFile()) {
            boolean isAllocated = indexServiceInjectorPair != null && indexServiceInjectorPair
                .getIndexService().hasShard(shardId.getId());
            if (isAllocated) {
                return false; // we are allocated - can't delete the shard
            }
            if (NodeEnvironment.hasCustomDataPath(indexSettings)) {
                // lets see if it's on a custom path (return false if the shared doesn't exist)
                // we don't need to delete anything that is not there
                return Files.exists(nodeEnv.resolveCustomLocation(indexSettings, shardId));
            } else {
                // lets see if it's path is available (return false if the shared doesn't exist)
                // we don't need to delete anything that is not there
                return FileSystemUtils.exists(nodeEnv.availableShardPaths(shardId));
            }
        }
    } else {
        logger.trace("{} skipping shard directory deletion due to shadow replicas", shardId);
    }
    return false;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:IndicesService.java


示例7: getWordList

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
/**
 * Fetches a list of words from the specified settings file. The list should either be available at the key
 * specified by settingsPrefix or in a file specified by settingsPrefix + _path.
 *
 * @throws IllegalArgumentException
 *          If the word list cannot be found at either key.
 */
public static List<String> getWordList(Environment env, Settings settings, String settingPrefix) {
    String wordListPath = settings.get(settingPrefix + "_path", null);

    if (wordListPath == null) {
        String[] explicitWordList = settings.getAsArray(settingPrefix, null);
        if (explicitWordList == null) {
            return null;
        } else {
            return Arrays.asList(explicitWordList);
        }
    }

    final Path wordListFile = env.configFile().resolve(wordListPath);

    try (BufferedReader reader = FileSystemUtils.newBufferedReader(wordListFile.toUri().toURL(), Charsets.UTF_8)) {
        return loadWordList(reader, "#");
    } catch (IOException ioe) {
        String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, ioe.getMessage());
        throw new IllegalArgumentException(message);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:29,代码来源:Analysis.java


示例8: getReaderFromFile

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
/**
 * @return null If no settings set for "settingsPrefix" then return <code>null</code>.
 * @throws IllegalArgumentException
 *          If the Reader can not be instantiated.
 */
public static Reader getReaderFromFile(Environment env, Settings settings, String settingPrefix) {
    String filePath = settings.get(settingPrefix, null);

    if (filePath == null) {
        return null;
    }

    final Path path = env.configFile().resolve(filePath);

    try {
        return FileSystemUtils.newBufferedReader(path.toUri().toURL(), Charsets.UTF_8);
    } catch (IOException ioe) {
        String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, ioe.getMessage());
        throw new IllegalArgumentException(message);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:Analysis.java


示例9: addMappings

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
private void addMappings(Map<String, Map<String, Object>> mappings, Path mappingsDir) throws IOException {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(mappingsDir)) {
        for (Path mappingFile : stream) {
            final String fileName = mappingFile.getFileName().toString();
            if (FileSystemUtils.isHidden(mappingFile)) {
                continue;
            }
            int lastDotIndex = fileName.lastIndexOf('.');
            String mappingType = lastDotIndex != -1 ? mappingFile.getFileName().toString().substring(0, lastDotIndex) : mappingFile.getFileName().toString();
            try (BufferedReader reader = Files.newBufferedReader(mappingFile, Charsets.UTF_8)) {
                String mappingSource = Streams.copyToString(reader);
                if (mappings.containsKey(mappingType)) {
                    XContentHelper.mergeDefaults(mappings.get(mappingType), parseMapping(mappingSource));
                } else {
                    mappings.put(mappingType, parseMapping(mappingSource));
                }
            } catch (Exception e) {
                logger.warn("failed to read / parse mapping [" + mappingType + "] from location [" + mappingFile + "], ignoring...", e);
            }
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:MetaDataCreateIndexService.java


示例10: testSpaceInUrl

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
public void testSpaceInUrl() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String pluginZip = createPlugin("fake", pluginDir);
    Path pluginZipWithSpaces = createTempFile("foo bar", ".zip");
    try (InputStream in = FileSystemUtils.openFileURLStream(new URL(pluginZip))) {
        Files.copy(in, pluginZipWithSpaces, StandardCopyOption.REPLACE_EXISTING);
    }
    installPlugin(pluginZipWithSpaces.toUri().toURL().toString(), env.v1());
    assertPlugin("fake", pluginDir, env.v2());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:InstallPluginCommandTests.java


示例11: testVerifyIfIndexContentDeleted

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
public void testVerifyIfIndexContentDeleted() throws Exception {
    final Index index = new Index("test", UUIDs.randomBase64UUID());
    final IndicesService indicesService = getIndicesService();
    final NodeEnvironment nodeEnv = getNodeEnvironment();
    final MetaStateService metaStateService = getInstanceFromNode(MetaStateService.class);

    final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
    final Settings idxSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
                                                    .put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID())
                                                    .build();
    final IndexMetaData indexMetaData = new IndexMetaData.Builder(index.getName())
                                                         .settings(idxSettings)
                                                         .numberOfShards(1)
                                                         .numberOfReplicas(0)
                                                         .build();
    metaStateService.writeIndex("test index being created", indexMetaData);
    final MetaData metaData = MetaData.builder(clusterService.state().metaData()).put(indexMetaData, true).build();
    final ClusterState csWithIndex = new ClusterState.Builder(clusterService.state()).metaData(metaData).build();
    try {
        indicesService.verifyIndexIsDeleted(index, csWithIndex);
        fail("Should not be able to delete index contents when the index is part of the cluster state.");
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), containsString("Cannot delete index"));
    }

    final ClusterState withoutIndex = new ClusterState.Builder(csWithIndex)
                                                      .metaData(MetaData.builder(csWithIndex.metaData()).remove(index.getName()))
                                                      .build();
    indicesService.verifyIndexIsDeleted(index, withoutIndex);
    assertFalse("index files should be deleted", FileSystemUtils.exists(nodeEnv.indexPaths(index)));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:IndicesServiceTests.java


示例12: 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


示例13: 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


示例14: testJarMetadata

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
/** Asking for the jar metadata should not throw exception in tests, no matter how configured */
public void testJarMetadata() throws IOException {
    URL url = Build.getElasticsearchCodebase();
    // throws exception if does not exist, or we cannot access it
    try (InputStream ignored = FileSystemUtils.openFileURLStream(url)) {}
    // these should never be null
    assertNotNull(Build.CURRENT.date());
    assertNotNull(Build.CURRENT.shortHash());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:BuildTests.java


示例15: readJsonResponse

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
private static String readJsonResponse(String url, String urlRoot) throws IOException {
    // We extract from the url the mock file path we want to use
    String mockFileName = Strings.replace(url, urlRoot, "");

    URL resource = GceMockUtils.class.getResource(mockFileName);
    if (resource == null) {
        throw new IOException("can't read [" + url + "] in src/test/resources/org/elasticsearch/discovery/gce");
    }
    try (InputStream is = FileSystemUtils.openFileURLStream(resource)) {
        final StringBuilder sb = new StringBuilder();
        Streams.readAllLines(is, sb::append);
        return sb.toString();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:GceMockUtils.java


示例16: getModuleBundles

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
static List<Bundle> getModuleBundles(Path modulesDirectory) throws IOException {
    // damn leniency
    if (Files.notExists(modulesDirectory)) {
        return Collections.emptyList();
    }
    List<Bundle> bundles = new ArrayList<>();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(modulesDirectory)) {
        for (Path module : stream) {
            if (FileSystemUtils.isHidden(module)) {
                continue; // skip over .DS_Store etc
            }
            PluginInfo info = PluginInfo.readFromProperties(module);
            if (!info.isJvm()) {
                throw new IllegalStateException("modules must be jvm plugins: " + info);
            }
            if (!info.isIsolated()) {
                throw new IllegalStateException("modules must be isolated: " + info);
            }
            Bundle bundle = new Bundle();
            bundle.plugins.add(info);
            // gather urls for jar files
            try (DirectoryStream<Path> jarStream = Files.newDirectoryStream(module, "*.jar")) {
                for (Path jar : jarStream) {
                    // normalize with toRealPath to get symlinks out of our hair
                    bundle.urls.add(jar.toRealPath().toUri().toURL());
                }
            }
            bundles.add(bundle);
        }
    }
    return bundles;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:33,代码来源:PluginsService.java


示例17: 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


示例18: 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


示例19: getLexiconPaths

import org.elasticsearch.common.io.FileSystemUtils; //导入依赖的package包/类
private List<Path> getLexiconPaths(Path lexiconPath) {
    if (Files.isDirectory(lexiconPath, LinkOption.NOFOLLOW_LINKS)) {
        try {
            return Arrays.asList(FileSystemUtils.files(lexiconPath, p -> p.startsWith("words") && p.endsWith(".dic")));
        } catch (IOException e) {
            log.error("load lexicon path: " + lexiconPath + " directory files have exception", e);
            throw new SettingsException("load lexicon path: " + lexiconPath + " directory files have exception", e);
        }
    } else {
        return Collections.singletonList(lexiconPath);
    }
}
 
开发者ID:wxingyl,项目名称:elasticsearch-analysis-benz,代码行数:13,代码来源:Config.java


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FormatException类代码示例发布时间:2022-05-22
下一篇:
Java DefaultRepositorySystem类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap