本文整理汇总了Java中java.nio.file.FileSystems.getFileSystem方法的典型用法代码示例。如果您正苦于以下问题:Java FileSystems.getFileSystem方法的具体用法?Java FileSystems.getFileSystem怎么用?Java FileSystems.getFileSystem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.FileSystems
的用法示例。
在下文中一共展示了FileSystems.getFileSystem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
synchronized (jarFileSystems) {
if (jarFileSystems.add(fileURI)) {
fileSystem = FileSystems.newFileSystem(fileURI, Collections.<String, Object>emptyMap());
} else {
fileSystem = FileSystems.getFileSystem(fileURI);
}
}
return fileSystem.getPath(entryName);
} else {
throw new IOException("Can't read " + resource + ", unknown protocol '" + protocol + "'");
}
}
示例2: setup
import java.nio.file.FileSystems; //导入方法依赖的package包/类
@BeforeClass
public void setup() {
theFileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
Path modulesPath = Paths.get(System.getProperty("java.home"),
"lib", "modules");
isExplodedBuild = Files.notExists(modulesPath);
if (isExplodedBuild) {
System.out.printf("%s doesn't exist.", modulesPath.toString());
System.out.println();
System.out.println("It is most probably an exploded build."
+ " Skip non-default FileSystem testing.");
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 {
fs = FileSystems.newFileSystem(URI.create("jrt:/"), env);
} catch (IOException ioExp) {
throw new RuntimeException(ioExp);
}
}
示例3: testRegexPathMatcher
import java.nio.file.FileSystems; //导入方法依赖的package包/类
@Test(dataProvider = "pathRegexPatterns")
public void testRegexPathMatcher(String pattern, String path,
boolean expectMatch) throws Exception {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
PathMatcher pm = fs.getPathMatcher("regex:" + pattern);
Path p = fs.getPath(path);
assertTrue(Files.exists(p), path);
assertTrue(!(pm.matches(p) ^ expectMatch),
p + (expectMatch? " should match " : " should not match ") +
pattern);
}
示例4: testNewFileSystem
import java.nio.file.FileSystems; //导入方法依赖的package包/类
@Test
public void testNewFileSystem() throws Exception {
FileSystem theFileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
Map<String, ?> env = Collections.emptyMap();
try (FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), env)) {
checkFileSystem(fs);
assertTrue(fs != theFileSystem);
}
}
示例5: getOrNewFileSystem
import java.nio.file.FileSystems; //导入方法依赖的package包/类
private FileSystem getOrNewFileSystem(URI uri) throws IOException {
try {
return FileSystems.getFileSystem(uri);
} catch (FileSystemNotFoundException exception) {
return FileSystems.newFileSystem(uri, new HashMap<>());
}
}
示例6: testNotExists
import java.nio.file.FileSystems; //导入方法依赖的package包/类
@Test(dataProvider = "topLevelPkgDirs")
public void testNotExists(String path) throws Exception {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
Path dir = fs.getPath(path);
// package directories should not be there at top level
assertTrue(Files.notExists(dir));
}
示例7: SystemModuleFinder
import java.nio.file.FileSystems; //导入方法依赖的package包/类
SystemModuleFinder() {
if (Files.isRegularFile(Paths.get(JAVA_HOME, "lib", "modules"))) {
// jrt file system
this.fileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
this.root = fileSystem.getPath("/modules");
this.systemModules = walk(root);
} else {
// exploded image
this.fileSystem = FileSystems.getDefault();
root = Paths.get(JAVA_HOME, "modules");
this.systemModules = ModuleFinder.ofSystem().findAll().stream()
.collect(toMap(mref -> mref.descriptor().name(), Function.identity()));
}
}
示例8: testGlobPathMatcher
import java.nio.file.FileSystems; //导入方法依赖的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);
}
示例9: testParentInDirList
import java.nio.file.FileSystems; //导入方法依赖的package包/类
public void testParentInDirList(String dir) throws Exception {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
Path base = fs.getPath(dir);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(base)) {
for (Path entry: stream) {
assertTrue( entry.getParent().equals(base),
base.toString() + "-> " + entry.toString() );
}
}
}
示例10: invalidPathTest
import java.nio.file.FileSystems; //导入方法依赖的package包/类
@Test
public void invalidPathTest() {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
InvalidPathException ipe = null;
try {
boolean res = Files.exists(fs.getPath("/packages/\ud834\udd7b"));
assertFalse(res);
return;
} catch (InvalidPathException e) {
ipe = e;
}
assertTrue(ipe != null);
}
示例11: testPackagesLinks
import java.nio.file.FileSystems; //导入方法依赖的package包/类
@Test(dataProvider = "packagesLinks")
public void testPackagesLinks(String link) throws Exception {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
Path path = fs.getPath(link);
assertTrue(Files.exists(path), link + " missing");
assertTrue(Files.isSymbolicLink(path), path + " is not a link");
path = Files.readSymbolicLink(path);
assertEquals(path.toString(), "/modules" + link.substring(link.lastIndexOf("/")));
}
示例12: testPackagesSubDirs
import java.nio.file.FileSystems; //导入方法依赖的package包/类
@Test(dataProvider = "packagesSubDirs")
public void testPackagesSubDirs(String pkg) throws Exception {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
assertTrue(Files.isDirectory(fs.getPath("/packages/" + pkg)),
pkg + " missing");
}
示例13: Helper
import java.nio.file.FileSystems; //导入方法依赖的package包/类
private Helper(Path jdkHome) throws IOException {
this.stdjmods = jdkHome.resolve("jmods").normalize();
if (!Files.exists(stdjmods)) {
throw new IOException("Standard jMods do not exist.");
}
this.fs = FileSystems.getFileSystem(URI.create("jrt:/"));
Path javabase = fs.getPath("/modules/java.base");
this.bootClasses = Files.find(javabase, Integer.MAX_VALUE,
(file, attrs) -> file.toString().endsWith(".class"))
.map(Object::toString)
.map(s -> s.substring("/modules".length()))
.collect(Collectors.toList());
if (bootClasses.isEmpty()) {
throw new AssertionError("No boot class to check against");
}
this.jmods = Paths.get("jmods").toAbsolutePath();
Files.createDirectories(jmods);
this.jars = Paths.get("jars").toAbsolutePath();
Files.createDirectories(jars);
this.explodedmods = Paths.get("explodedmods").toAbsolutePath();
Files.createDirectories(explodedmods);
this.explodedmodssrc = explodedmods.resolve("src");
Files.createDirectories(explodedmodssrc);
this.jarssrc = jars.resolve("src");
Files.createDirectories(jarssrc);
this.jmodssrc = jmods.resolve("src");
Files.createDirectories(jmodssrc);
this.explodedmodsclasses = explodedmods.resolve("classes");
Files.createDirectories(explodedmodsclasses);
this.jmodsclasses = jmods.resolve("classes");
Files.createDirectories(jmodsclasses);
this.jarsclasses = jars.resolve("classes");
Files.createDirectories(jarsclasses);
this.images = Paths.get("images").toAbsolutePath();
Files.createDirectories(images);
this.extracted = Paths.get("extracted").toAbsolutePath();
Files.createDirectories(extracted);
this.recreated = Paths.get("recreated").toAbsolutePath();
Files.createDirectories(recreated);
}
示例14: JRTIndex
import java.nio.file.FileSystems; //导入方法依赖的package包/类
/**
* Create and initialize the index.
*/
private JRTIndex() throws IOException {
jrtfs = FileSystems.getFileSystem(URI.create("jrt:/"));
entries = new HashMap<>();
}
示例15: getJrtFileSystem
import java.nio.file.FileSystems; //导入方法依赖的package包/类
private FileSystem getJrtFileSystem() {
return FileSystems.getFileSystem(URI.create("jrt:/"));
}