當前位置: 首頁>>代碼示例>>Java>>正文


Java FileSystems.newFileSystem方法代碼示例

本文整理匯總了Java中java.nio.file.FileSystems.newFileSystem方法的典型用法代碼示例。如果您正苦於以下問題:Java FileSystems.newFileSystem方法的具體用法?Java FileSystems.newFileSystem怎麽用?Java FileSystems.newFileSystem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.file.FileSystems的用法示例。


在下文中一共展示了FileSystems.newFileSystem方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onTest

import java.nio.file.FileSystems; //導入方法依賴的package包/類
@Test
public void onTest() throws Exception {
    File testZip = new File("test.zip");
    JarFile jarFile = new JarFile(testZip);
    jarFile.stream().forEach((jarEntry -> {
        System.out.println(jarEntry.getName());
        if (jarEntry.getName().lastIndexOf('/') != -1) {
            System.out.println( "parent -> " + jarEntry.getName().substring(0, jarEntry
                    .getName()
                    .lastIndexOf('/')));
        }
    }));
    System.out.println("Filesystems");
    FileSystem fileSystem = FileSystems.newFileSystem(testZip.toPath(), null);
    Path meow = fileSystem.getPath("meow/");
    Files.list(meow).forEach((path) -> System.out.println(path.getFileName()));
}
 
開發者ID:PizzaCrust,項目名稱:Passion,代碼行數:18,代碼來源:JavaTesting.java

示例2: ArchiveContainer

import java.nio.file.FileSystems; //導入方法依賴的package包/類
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException {
    this.archivePath = archivePath;
    if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) {
        Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue);
        FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
        Assert.checkNonNull(jarFSProvider, "should have been caught before!");
        this.fileSystem = jarFSProvider.newFileSystem(archivePath, env);
    } else {
        this.fileSystem = FileSystems.newFileSystem(archivePath, null);
    }
    packages = new HashMap<>();
    for (Path root : fileSystem.getRootDirectories()) {
        Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                        if (isValid(dir.getFileName())) {
                            packages.put(new RelativeDirectory(root.relativize(dir).toString()), dir);
                            return FileVisitResult.CONTINUE;
                        } else {
                            return FileVisitResult.SKIP_SUBTREE;
                        }
                    }
                });
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:JavacFileManager.java

示例3: validate

import java.nio.file.FileSystems; //導入方法依賴的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.FileSystems; //導入方法依賴的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: testNewFileSystemWithJavaHome

import java.nio.file.FileSystems; //導入方法依賴的package包/類
@Test
public void testNewFileSystemWithJavaHome() throws Exception {
    if (isExplodedBuild) {
        System.out.println("Skip testNewFileSystemWithJavaHome"
                + " since this is an exploded build");
        return;
    }

    Map<String, String> env = new HashMap<>();
    // set java.home property to be underlying java.home
    // so that jrt-fs.jar loading is exercised.
    env.put("java.home", System.getProperty("java.home"));
    try (FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), env)) {
        checkFileSystem(fs);
        // jrt-fs.jar classes are loaded by another (non-boot) loader in this case
        assertNotNull(fs.provider().getClass().getClassLoader());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Basic.java

示例6: testZipRepoContent

import java.nio.file.FileSystems; //導入方法依賴的package包/類
@Test
public void testZipRepoContent() throws Exception {
    Path repoDir = Paths.get(getClass().getResource(repository).toURI());
    Path mtarZip = null;
    try {
        mtarZip = step.zipRepoContent(repoDir.toAbsolutePath());
        URI jarMtarUri = URI.create("jar:" + mtarZip.toAbsolutePath().toUri().toString());
        try (FileSystem mtarFS = FileSystems.newFileSystem(jarMtarUri, new HashMap<>())) {
            Path mtarRoot = mtarFS.getRootDirectories().iterator().next();
            assertFalse(Files.exists(mtarRoot.resolve(".git")));
            assertFalse(Files.exists(mtarRoot.resolve(".gitignore")));
            assertTrue(Files.exists(mtarRoot.resolve("a/cool-script.script")));
            assertTrue(Files.exists(mtarRoot.resolve("META-INF/mtad.yaml")));
            assertTrue(Files.exists(mtarRoot.resolve("META-INF/MANIFEST.MF")));
        }
    } finally {
        if (mtarZip != null) {
            Files.deleteIfExists(mtarZip);
        }
    }
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:22,代碼來源:ProcessGitSourceStepTest.java

示例7: checkModule

import java.nio.file.FileSystems; //導入方法依賴的package包/類
private static void checkModule(String mn, String... packages) throws IOException {
    // verify ModuleDescriptor from the runtime module
    ModuleDescriptor md = ModuleLayer.boot().findModule(mn).get()
                               .getDescriptor();
    checkModuleDescriptor(md, packages);

    // verify ModuleDescriptor from module-info.class read from ModuleReader
    try (InputStream in = ModuleFinder.ofSystem().find(mn).get()
        .open().open("module-info.class").get()) {
        checkModuleDescriptor(ModuleDescriptor.read(in), packages);
    }

    // verify ModuleDescriptor from module-info.class read from jimage
    FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), Map.of());
    Path path = fs.getPath("/", "modules", mn, "module-info.class");
    checkModuleDescriptor(ModuleDescriptor.read(Files.newInputStream(path)), packages);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:Main.java

示例8: readFromPath

import java.nio.file.FileSystems; //導入方法依賴的package包/類
/** Returns the application info read from either an app folder or ipa archive */
public static IosAppInfo readFromPath(Path ipaOrAppPath) throws IOException {
  NSObject plistDict;
  if (Files.isDirectory(ipaOrAppPath)) {
    plistDict = PlistParser.fromPath(ipaOrAppPath.resolve("Info.plist"));
  } else {
    try (FileSystem ipaFs = FileSystems.newFileSystem(ipaOrAppPath, null)) {
      Path appPath =
          MoreFiles.listFiles(ipaFs.getPath("Payload"))
              .stream()
              // Can't use Files.isDirectory, because no entry is a "directory" in a zip.
              .filter(e -> e.toString().endsWith(".app/"))
              .collect(MoreCollectors.onlyElement());
      plistDict = PlistParser.fromPath(appPath.resolve("Info.plist"));
    }
  }
  return readFromPlistDictionary((NSDictionary) plistDict);
}
 
開發者ID:google,項目名稱:ios-device-control,代碼行數:19,代碼來源:IosAppInfo.java

示例9: deserialize

import java.nio.file.FileSystems; //導入方法依賴的package包/類
private static synchronized Level deserialize(Path levelZip) throws IOException {
    FileSystem fileSystem = FileSystems.newFileSystem(levelZip, null);
    levelFile = fileSystem;
    
    Path jsonPath = fileSystem.getPath("level.json");
    
    EventBus eventBus = SpaceGame.getInstance().getEventBus();
    Object   ler      = SpaceGame.getInstance().getContext().createLevelEventHandler(fileSystem);
    eventBus.registerAnnotated(ler);
    
    SpaceGame.getInstance().getContext().reload();
    
    Level level = SpaceGame.getInstance().getGson().fromJson(Files.newBufferedReader(jsonPath), Level.class);
    _deserializing = null;
    levelFile = null;
    level.init(ler);
    return level;
}
 
開發者ID:SergeySave,項目名稱:SpaceGame,代碼行數:19,代碼來源:Level.java

示例10: toPath

import java.nio.file.FileSystems; //導入方法依賴的package包/類
/**
 * Convert a local URL (file:// or jar:// protocol) to a {@link Path}
 * @param resource the URL resource
 * @return the Path
 * @throws URISyntaxException
 * @throws IOException
 */
public static Path toPath(URL resource) throws IOException, URISyntaxException {
    if (resource == null) return null;

    final String protocol = resource.getProtocol();
    if ("file".equals(protocol)) {
        return Paths.get(resource.toURI());
    } else if ("jar".equals(protocol)) {
        final String s = resource.toString();
        final int separator = s.indexOf("!/");
        final String entryName = s.substring(separator + 2);
        final URI fileURI = URI.create(s.substring(0, separator));

        final FileSystem fileSystem;
        if (!jarFileSystems.contains(fileURI))
            synchronized (jarFileSystems) {
                if (jarFileSystems.add(fileURI)) {
                    fileSystem = FileSystems.newFileSystem(fileURI, Collections.<String, Object>emptyMap());
                } else {
                    fileSystem = FileSystems.getFileSystem(fileURI);
                }
            } else {
            fileSystem = FileSystems.getFileSystem(fileURI);
        }
        return fileSystem.getPath(entryName);
    } else {
        throw new IllegalArgumentException("Can't read " + resource + ", unknown protocol '" + protocol + "'");
    }
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:36,代碼來源:FileSystemUtils.java

示例11: main

import java.nio.file.FileSystems; //導入方法依賴的package包/類
public static void main(String... args) throws Exception {
    int count = args.length > 0 ? Integer.valueOf(args[0]) : 0;
    if (count < 1 || args.length != count*2+1) {
        throw new IllegalArgumentException(Arrays.toString(args));
    }

    List<String> modules = List.of(Arrays.copyOfRange(args, 1, 1+count));
    List<String> versions = List.of(Arrays.copyOfRange(args, 1+count, args.length));
    for (int i=0; i < modules.size(); i++) {
        System.out.format("module %s expects %s version%n",
                          modules.get(i), versions.get(i));
        nameToVersion.put(modules.get(i), versions.get(i));
    }

    FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"),
                                              Collections.emptyMap());
    // check the module descriptor of a system module
    for (int i=0; i < modules.size(); i++) {
        String mn = modules.get(i);
        Module module = ModuleLayer.boot().findModule(mn).orElseThrow(
            () -> new RuntimeException(mn + " not found")
        );

        // check ModuleDescriptor from the run-time
        validate(module.getDescriptor());

        // check module-info.class in the image
        Path path = fs.getPath("/", "modules", modules.get(i), "module-info.class");
        validate(ModuleDescriptor.read(Files.newInputStream(path)));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:Main.java

示例12: testJarFSPath

import java.nio.file.FileSystems; //導入方法依賴的package包/類
@Test
public void testJarFSPath(Path base) throws IOException {
    // Test that we can look up in non-default file systems on the search path,
    // such as an open jar file system.
    Path src = base.resolve("src");
    tb.writeJavaFiles(src, "package p; class C { }");
    Path classes = Files.createDirectories(base.resolve("classes"));
    new JavacTask(tb)
        .options("-sourcepath", src.toString())
        .outdir(classes)
        .files(findJavaFiles(src))
        .run()
        .writeAll();

    Path jar = base.resolve("classes.jar");
    new JarTask(tb).run("cf", jar.toString(), "-C", classes.toString(), "p");

    Path c = src.resolve("p/C.java");
    Path x = base.resolve("src2/p/C.java");

    try (FileSystem jarFS = FileSystems.newFileSystem(jar, null);
            StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
        Path jarRoot = jarFS.getRootDirectories().iterator().next();
        fm.setLocationFromPaths(StandardLocation.CLASS_PATH, List.of(src, jarRoot));

        checkContains(fm, StandardLocation.CLASS_PATH, c, true);
        checkContains(fm, StandardLocation.CLASS_PATH, x, false);

        JavaFileObject fo = fm.list(StandardLocation.CLASS_PATH, "p",
                EnumSet.of(JavaFileObject.Kind.CLASS), false).iterator().next();

        checkContains(fm, StandardLocation.CLASS_PATH, fo, true);
        checkContains(fm, StandardLocation.CLASS_PATH, jarRoot.resolve("p/C.class"), true);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:ContainsTest.java

示例13: getClassNames

import java.nio.file.FileSystems; //導入方法依賴的package包/類
@Override
public List<String> getClassNames() throws IOException {
    Set<String> negative = new HashSet<>();
    Set<String> positive = new HashSet<>();
    if (limitModules != null && !limitModules.isEmpty()) {
        for (String s : limitModules.split(",")) {
            if (s.startsWith("~")) {
                negative.add(s.substring(1));
            } else {
                positive.add(s);
            }
        }
    }
    List<String> classNames = new ArrayList<>();
    FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), Collections.emptyMap());
    Path top = fs.getPath("/modules/");
    Files.find(top, Integer.MAX_VALUE,
                    (path, attrs) -> attrs.isRegularFile()).forEach(p -> {
                        int nameCount = p.getNameCount();
                        if (nameCount > 2) {
                            String base = p.getName(nameCount - 1).toString();
                            if (base.endsWith(".class") && !base.equals("module-info.class")) {
                                String module = p.getName(1).toString();
                                if (positive.isEmpty() || positive.contains(module)) {
                                    if (negative.isEmpty() || !negative.contains(module)) {
                                        // Strip module prefix and convert to dotted form
                                        String className = p.subpath(2, nameCount).toString().replace('/', '.');
                                        // Strip ".class" suffix
                                        className = className.replace('/', '.').substring(0, className.length() - ".class".length());
                                        classNames.add(className);
                                    }
                                }
                            }
                        }
                    });
    return classNames;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:38,代碼來源:CompileTheWorld.java

示例14: listModularRuntime

import java.nio.file.FileSystems; //導入方法依賴的package包/類
private Set<String> listModularRuntime(Path javaHome) throws IOException {
    Map<String, String> env = new HashMap<>();
    env.put("java.home", javaHome.toString());
    FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), env);
    Path root = fs.getPath("packages");
    return Files.walk(root, 1)
                .map(Path::getFileName)
                .map(Path::toString)
                .collect(Collectors.toSet());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:ListPackages.java

示例15: copyResources

import java.nio.file.FileSystems; //導入方法依賴的package包/類
@Override
public void copyResources(File dir) throws URISyntaxException, IOException {
  
  if (!hasResources())
    throw new UnsupportedOperationException(
        "this plugin doesn't have any resources you can copy as you would know had you called hasResources first :P");
  
  try (FileSystem zipFs =
      FileSystems.newFileSystem(artifactURL.toURI(), new HashMap<>());) {

    Path target = Paths.get(dir.toURI());
    Path pathInZip = zipFs.getPath("/resources");

    Files.walkFileTree(pathInZip, new SimpleFileVisitor<Path>() {
      @Override
      public FileVisitResult visitFile(Path filePath,
          BasicFileAttributes attrs) throws IOException {
        // Make sure that we conserve the hierachy of files and folders
        // inside the zip
        Path relativePathInZip = pathInZip.relativize(filePath);
        Path targetPath = target.resolve(relativePathInZip.toString());
        Files.createDirectories(targetPath.getParent());

        // And extract the file
        Files.copy(filePath, targetPath, StandardCopyOption.REPLACE_EXISTING);

        return FileVisitResult.CONTINUE;
      }
    });
  }
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:32,代碼來源:Plugin.java


注:本文中的java.nio.file.FileSystems.newFileSystem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。