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


Java FileSystem.getPath方法代码示例

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


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

示例1: copyJavaBase

import java.nio.file.FileSystem; //导入方法依赖的package包/类
private void copyJavaBase(Path targetDir) throws IOException {
    FileSystem jrt = FileSystems.getFileSystem(URI.create("jrt:/"));
    Path javaBase = jrt.getPath("modules", "java.base");

    if (!Files.exists(javaBase)) {
        throw new AssertionError("No java.base?");
    }

    Path javaBaseClasses = targetDir.resolve("java.base");

    for (Path clazz : tb.findFiles("class", javaBase)) {
        Path target = javaBaseClasses.resolve(javaBase.relativize(clazz).toString());
        Files.createDirectories(target.getParent());
        Files.copy(clazz, target);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:IncubatingTest.java

示例2: testExtractBatchSpreadsheetWithArea

import java.nio.file.FileSystem; //导入方法依赖的package包/类
@Test
public void testExtractBatchSpreadsheetWithArea() throws ParseException, IOException {
    FileSystem fs = FileSystems.getDefault();
    String expectedCsv = UtilsForTesting.loadCsv("src/test/resources/technology/tabula/csv/spreadsheet_no_bounding_frame.csv");
    Path tmpFolder = Files.createTempDirectory("tabula-java-batch-test");
    tmpFolder.toFile().deleteOnExit();

    Path copiedPDF = tmpFolder.resolve(fs.getPath("spreadsheet.pdf"));
    Path sourcePDF = fs.getPath("src/test/resources/technology/tabula/spreadsheet_no_bounding_frame.pdf");
    Files.copy(sourcePDF, copiedPDF);
    copiedPDF.toFile().deleteOnExit();

    this.csvFromCommandLineArgs(new String[]{
            "-b", tmpFolder.toString(),
            "-p", "1", "-a",
            "150.56,58.9,654.7,536.12", "-f",
            "CSV"
    });

    Path csvPath = tmpFolder.resolve(fs.getPath("spreadsheet.csv"));
    assertTrue(csvPath.toFile().exists());
    assertArrayEquals(expectedCsv.getBytes(), Files.readAllBytes(csvPath));
}
 
开发者ID:redmyers,项目名称:484_P7_1-Java,代码行数:24,代码来源:TestCommandLineApp.java

示例3: validate

import java.nio.file.FileSystem; //导入方法依赖的package包/类
static void validate(Module module) throws IOException {
    ModuleDescriptor md = module.getDescriptor();

    // read m1/module-info.class
    FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"),
                                              Collections.emptyMap());
    Path path = fs.getPath("/", "modules", module.getName(), "module-info.class");
    ModuleDescriptor md1 = ModuleDescriptor.read(Files.newInputStream(path));


    // check the module descriptor of a system module and read from jimage
    checkPackages(md.packages(), "p1", "p2");
    checkPackages(md1.packages(), "p1", "p2");

    try (InputStream in = Files.newInputStream(path)) {
        checkModuleTargetAttribute(in, "p1");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Main.java

示例4: main

import java.nio.file.FileSystem; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
    // load another package
    p2.T.test();

    // validate the module descriptor
    validate(Main.class.getModule());

    // validate the Moduletarget attribute for java.base
    FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"),
                                              Collections.emptyMap());
    Path path = fs.getPath("/", "modules", "java.base", "module-info.class");
    try (InputStream in = Files.newInputStream(path)) {
        if (! hasModuleTarget(in)) {
            throw new RuntimeException("Missing ModuleTarget for java.base");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Main.java

示例5: getLauncher

import java.nio.file.FileSystem; //导入方法依赖的package包/类
private static String[] getLauncher() throws IOException {
    String platform = getPlatform();
    if (platform == null) {
        return null;
    }

    String launcher = TEST_SRC + File.separator + platform + "-" + ARCH +
                      File.separator + "launcher";

    final FileSystem FS = FileSystems.getDefault();
    Path launcherPath = FS.getPath(launcher);

    final boolean hasLauncher = Files.isRegularFile(launcherPath, LinkOption.NOFOLLOW_LINKS)&&
                                Files.isReadable(launcherPath);
    if (!hasLauncher) {
        System.out.println("Launcher [" + launcher + "] does not exist. Skipping the test.");
        return null;
    }

    // It is impossible to store an executable file in the source control
    // We need to copy the launcher to the working directory
    // and set the executable flag
    Path localLauncherPath = FS.getPath(WORK_DIR, "launcher");
    Files.copy(launcherPath, localLauncherPath,
               StandardCopyOption.REPLACE_EXISTING,
               StandardCopyOption.COPY_ATTRIBUTES);
    if (!Files.isExecutable(localLauncherPath)) {
        Set<PosixFilePermission> perms = new HashSet<>(
            Files.getPosixFilePermissions(
                localLauncherPath,
                LinkOption.NOFOLLOW_LINKS
            )
        );
        perms.add(PosixFilePermission.OWNER_EXECUTE);
        Files.setPosixFilePermissions(localLauncherPath, perms);
    }
    return new String[] {launcher, localLauncherPath.toAbsolutePath().toString()};
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:CustomLauncherTest.java

示例6: installDirectlyFromGitHub2

import java.nio.file.FileSystem; //导入方法依赖的package包/类
@Test
public void installDirectlyFromGitHub2() throws Exception {

    final FileSystem fs = Jimfs.newFileSystem();

    // Workaround: JimFs does not implement .toFile;
    // We clone and fail buckaroo-recipes if it does not exist, so we create it.
    MoreFiles.createParentDirectories(fs.getPath(
        System.getProperty("user.home"),
        ".buckaroo",
        "buckaroo-recipes",
        ".git"));

    final ImmutableList<PartialDependency> partialDependencies = ImmutableList.of(
        PartialDependency.of(
            Identifier.of("github"),
            Identifier.of("njlr"),
            Identifier.of("test-lib-d"),
            AnySemanticVersion.of()));

    InitTasks.initWorkingDirectory(fs).toList().blockingGet();

    InstallTasks.installDependencyInWorkingDirectory(fs, partialDependencies).toList().blockingGet();

    assertTrue(Files.exists(fs.getPath("BUCKAROO_DEPS")));

    final Path dependencyFolder = fs.getPath(
        "buckaroo", "github", "njlr", "test-lib-d");

    assertTrue(Files.exists(dependencyFolder.resolve("BUCK")));
    assertTrue(Files.exists(dependencyFolder.resolve("BUCKAROO_DEPS")));
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:33,代码来源:InstallTasksTest.java

示例7: writeDoesNotOverwrite

import java.nio.file.FileSystem; //导入方法依赖的package包/类
@Test(expected=IOException.class)
public void writeDoesNotOverwrite() throws Exception {

    final FileSystem fs = Jimfs.newFileSystem();
    final Path path = fs.getPath("test.txt");

    EvenMoreFiles.writeFile(path, "Testing... testing...");
    EvenMoreFiles.writeFile(path, "123");
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:10,代码来源:EvenMoreFilesTest.java

示例8: testGlobPathMatcher

import java.nio.file.FileSystem; //导入方法依赖的package包/类
@Test(dataProvider = "pathGlobPatterns")
public void testGlobPathMatcher(String pattern, String path,
        boolean expectMatch) throws Exception {
    FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
    PathMatcher pm = fs.getPathMatcher("glob:" + pattern);
    Path p = fs.getPath(path);
    assertTrue(Files.exists(p), path);
    assertTrue(!(pm.matches(p) ^ expectMatch),
        p + (expectMatch? " should match " : " should not match ") +
        pattern);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:Basic.java

示例9: switchFileSystem

import java.nio.file.FileSystem; //导入方法依赖的package包/类
@Test
public void switchFileSystem() throws Exception {

    final FileSystem fs1 = Jimfs.newFileSystem();
    final FileSystem fs2 = Jimfs.newFileSystem();

    final Path path1 = fs1.getPath("a", "b", "c");
    final Path path2 = EvenMoreFiles.switchFileSystem(fs2, path1);
    final Path path3 = EvenMoreFiles.switchFileSystem(fs1, path2);

    assertEquals(path1, path3);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:13,代码来源:EvenMoreFilesTest.java

示例10: toSafeFilePath

import java.nio.file.FileSystem; //导入方法依赖的package包/类
/**
 * Map a resource name to a "safe" file path. Returns {@code null} if
 * the resource name cannot be converted into a "safe" file path.
 *
 * Resource names with empty elements, or elements that are "." or ".."
 * are rejected, as are resource names that translates to a file path
 * with a root component.
 */
private static Path toSafeFilePath(FileSystem fs, String name) {
    // scan elements of resource name
    int next;
    int off = 0;
    while ((next = name.indexOf('/', off)) != -1) {
        int len = next - off;
        if (!mayTranslate(name, off, len)) {
            return null;
        }
        off = next + 1;
    }
    int rem = name.length() - off;
    if (!mayTranslate(name, off, rem)) {
        return null;
    }

    // convert to file path
    Path path;
    if (File.separatorChar == '/') {
        path = fs.getPath(name);
    } else {
        // not allowed to embed file separators
        if (name.contains(File.separator))
            return null;
        path = fs.getPath(name.replace('/', File.separatorChar));
    }

    // file path not allowed to have root component
    return (path.getRoot() == null) ? path : null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:Resources.java

示例11: installDirectlyFromGitHub1

import java.nio.file.FileSystem; //导入方法依赖的package包/类
@Test
public void installDirectlyFromGitHub1() throws Exception {

    final FileSystem fs = Jimfs.newFileSystem();

    // Workaround: JimFs does not implement .toFile;
    // We clone and fail buckaroo-recipes if it does not exist, so we create it.
    MoreFiles.createParentDirectories(fs.getPath(
        System.getProperty("user.home"),
        ".buckaroo",
        "buckaroo-recipes",
        ".git"));

    final ImmutableList<PartialDependency> partialDependencies = ImmutableList.of(
        PartialDependency.of(
            Identifier.of("github"),
            Identifier.of("njlr"),
            Identifier.of("test-lib-a"),
            AnySemanticVersion.of()));

    InitTasks.initWorkingDirectory(fs).toList().blockingGet();

    final List<Event> events = InstallTasks.installDependencyInWorkingDirectory(fs, partialDependencies).toList().blockingGet();

    assertTrue(Files.exists(fs.getPath("BUCKAROO_DEPS")));

    final Path dependencyFolder = fs.getPath(
        "buckaroo", "github", "njlr", "test-lib-a");

    assertTrue(Files.exists(dependencyFolder.resolve("BUCK")));
    assertTrue(Files.exists(dependencyFolder.resolve("BUCKAROO_DEPS")));
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:33,代码来源:InstallTasksTest.java

示例12: testSameFile

import java.nio.file.FileSystem; //导入方法依赖的package包/类
@Test
public void testSameFile() {
    final FileSystem fs = FileSystems.getDefault();
    final Path baseName = fs.getPath("/tmp", "logfile.log");
    final ExactFileStrategy m = new ExactFileStrategy(baseName);

    assertTrue("same file matches", m.pathMatches(fs.getPath("/tmp", "logfile.log")));
    assertTrue("paths are normalized", m.pathMatches(fs.getPath("/tmp/foo/..", "logfile.log")));
    assertFalse("only the same file name matches", m.pathMatches(fs.getPath("/tmp", "logfile.log.1")));
    assertTrue("relative paths are resolved", m.pathMatches(fs.getPath("logfile.log")));
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:12,代码来源:FileNamingStrategyTest.java

示例13: getPathWithParents

import java.nio.file.FileSystem; //导入方法依赖的package包/类
static Path getPathWithParents(FileSystem fs, String name)
    throws Exception
{
    Path path = fs.getPath(name);
    Path parent = path.getParent();
    if (parent != null && Files.notExists(parent))
        mkdirs(parent);
    return path;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:ZipFSTester.java

示例14: setupEnv

import java.nio.file.FileSystem; //导入方法依赖的package包/类
void setupEnv(boolean posix) throws IOException {
    final Configuration configuration;
    if (posix) {
        configuration = Configuration.unix().toBuilder().setAttributeViews("basic", "owner", "posix", "unix").build();
    } else {
        configuration = Configuration.unix();
    }
    FileSystem fs = Jimfs.newFileSystem(configuration);
    fileSystems.add(fs);
    PathUtilsForTesting.installMock(fs); // restored by restoreFileSystem in ESTestCase
    Path home = fs.getPath("/", "test-home");
    Files.createDirectories(home.resolve("config"));
    env = new Environment(Settings.builder().put("path.home", home).build());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:KeyStoreCommandTestCase.java

示例15: main

import java.nio.file.FileSystem; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    String javaHome = args[0];
    FileSystem fs = null;
    boolean isInstalled = false;
    if (args.length == 2) {
        fs = createFsByInstalledProvider();
        isInstalled = true;
    } else {
        fs = createFsWithURLClassloader(javaHome);
    }

    Path mods = fs.getPath("/modules");
    try (Stream<Path> stream = Files.walk(mods)) {
        stream.forEach(path -> {
            path.getFileName();
        });
    } finally {
        try {
            fs.close();
        } catch (UnsupportedOperationException e) {
            if (!isInstalled) {
                throw new RuntimeException(
                    "UnsupportedOperationException is thrown unexpectedly");
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:Main.java


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