java.nio.file.Path#getFileSystem ( )源码实例Demo

下面列出了java.nio.file.Path#getFileSystem ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public <V extends FileAttributeView> V getFileAttributeView(Path path,
		Class<V> type, LinkOption... options) {
	BundleFileSystem fs = (BundleFileSystem) path.getFileSystem();
	if (path.toAbsolutePath().equals(fs.getRootDirectory())) {
		// Bug in ZipFS, it will fall over as there is no entry for /
		//
		// Instead we'll just give a view of the source (e.g. the zipfile
		// itself).
		// Modifying its times is a bit futile since they are likely to be
		// overriden when closing, but this avoids a NullPointerException
		// in Files.setTimes().
		return Files.getFileAttributeView(fs.getSource(), type, options);
	}
	return origProvider(path).getFileAttributeView(fs.unwrap(path), type,
			options);
}
 
源代码2 项目: buck   文件: AppleSdkDiscoveryTest.java
@Test
public void shouldNotCrashOnBrokenSymlink() throws IOException {
  ProjectWorkspace workspace =
      TestDataHelper.createProjectWorkspaceForScenario(this, "sdk-discovery-symlink", temp);
  workspace.setUp();
  Path root = workspace.getPath("");
  FileSystem fileSystem = root.getFileSystem();

  Path sdksDir = root.resolve("Platforms/MacOSX.platform/Developer/SDKs");
  Files.createDirectories(sdksDir);
  CreateSymlinksForTests.createSymLink(
      sdksDir.resolve("MacOSX.sdk"), fileSystem.getPath("does_not_exist"));

  ImmutableMap<String, AppleToolchain> toolchains =
      ImmutableMap.of("com.apple.dt.toolchain.XcodeDefault", getDefaultToolchain(root));

  ImmutableMap<AppleSdk, AppleSdkPaths> actual =
      AppleSdkDiscovery.discoverAppleSdkPaths(
          Optional.of(root),
          ImmutableList.of(root),
          toolchains,
          FakeBuckConfig.builder().build().getView(AppleConfig.class));

  assertThat(actual.size(), is(0));
}
 
源代码3 项目: openjdk-jdk9   文件: Main.java
public static void main(String[] args) throws Exception {
    FileSystem fs = FileSystems.getDefault();
    if (fs.getClass().getModule() == Object.class.getModule())
        throw new RuntimeException("FileSystemProvider not overridden");

    // exercise the file system
    Path dir = Files.createTempDirectory("tmp");
    if (dir.getFileSystem() != fs)
        throw new RuntimeException("'dir' not in default file system");
    System.out.println("created: " + dir);

    Path foo = Files.createFile(dir.resolve("foo"));
    if (foo.getFileSystem() != fs)
        throw new RuntimeException("'foo' not in default file system");
    System.out.println("created: " + foo);

    // exercise interop with java.io.File
    File file = foo.toFile();
    Path path = file.toPath();
    if (path.getFileSystem() != fs)
        throw new RuntimeException("'path' not in default file system");
    if (!path.equals(foo))
        throw new RuntimeException(path + " not equal to " + foo);
}
 
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
		final Filter<? super Path> filter) throws IOException {
	final BundleFileSystem fs = (BundleFileSystem) dir.getFileSystem();
	final DirectoryStream<Path> stream = origProvider(dir)
			.newDirectoryStream(fs.unwrap(dir), new Filter<Path>() {
				@Override
				public boolean accept(Path entry) throws IOException {
					return filter.accept(fs.wrap(entry));
				}
			});
	return new DirectoryStream<Path>() {
		@Override
		public void close() throws IOException {
			stream.close();
		}

		@Override
		public Iterator<Path> iterator() {
			return fs.wrapIterator(stream.iterator());
		}
	};
}
 
@Override
public void setAttribute(Path path, String attribute, Object value,
		LinkOption... options) throws IOException {
	BundleFileSystem fs = (BundleFileSystem) path.getFileSystem();
	origProvider(path).setAttribute(fs.unwrap(path), attribute, value,
			options);
}
 
源代码6 项目: jimfs   文件: JimfsFileSystemProvider.java
@Override
public AsynchronousFileChannel newAsynchronousFileChannel(
    Path path,
    Set<? extends OpenOption> options,
    @NullableDecl ExecutorService executor,
    FileAttribute<?>... attrs)
    throws IOException {
  // call newFileChannel and cast so that FileChannel support is checked there
  JimfsFileChannel channel = (JimfsFileChannel) newFileChannel(path, options, attrs);
  if (executor == null) {
    JimfsFileSystem fileSystem = (JimfsFileSystem) path.getFileSystem();
    executor = fileSystem.getDefaultThreadPool();
  }
  return channel.asAsynchronousFileChannel(executor);
}
 
源代码7 项目: openjdk-jdk8u   文件: FaultyFileSystem.java
FaultyFileSystem(Path root) throws IOException {
    if (root == null) {
        root = Files.createTempDirectory("faultyFS");
        removeRootAfterClose = true;
    } else {
        if (! Files.isDirectory(root)) {
            throw new IllegalArgumentException("must be a directory.");
        }
        removeRootAfterClose = false;
    }
    this.root = root;
    delegate = root.getFileSystem();
    isOpen = true;
}
 
源代码8 项目: openjdk-jdk8u-backup   文件: FaultyFileSystem.java
FaultyFileSystem(Path root) throws IOException {
    if (root == null) {
        root = Files.createTempDirectory("faultyFS");
        removeRootAfterClose = true;
    } else {
        if (! Files.isDirectory(root)) {
            throw new IllegalArgumentException("must be a directory.");
        }
        removeRootAfterClose = false;
    }
    this.root = root;
    delegate = root.getFileSystem();
    isOpen = true;
}
 
源代码9 项目: openjdk-jdk9   文件: Locations.java
private boolean contains(Collection<Path> searchPath, Path file) throws IOException {

        if (searchPath == null) {
            return false;
        }

        Path enclosingJar = null;
        if (file.getFileSystem().provider() == fsInfo.getJarFSProvider()) {
            URI uri = file.toUri();
            if (uri.getScheme().equals("jar")) {
                String ssp = uri.getSchemeSpecificPart();
                int sep = ssp.lastIndexOf("!");
                if (ssp.startsWith("file:") && sep > 0) {
                    enclosingJar = Paths.get(URI.create(ssp.substring(0, sep)));
                }
            }
        }

        Path nf = normalize(file);
        for (Path p : searchPath) {
            Path np = normalize(p);
            if (np.getFileSystem() == nf.getFileSystem()
                    && Files.isDirectory(np)
                    && nf.startsWith(np)) {
                return true;
            }
            if (enclosingJar != null
                    && Files.isSameFile(enclosingJar, np)) {
                return true;
            }
        }

        return false;
    }
 
源代码10 项目: jdk8u-dev-jdk   文件: FaultyFileSystem.java
FaultyFileSystem(Path root) throws IOException {
    if (root == null) {
        root = Files.createTempDirectory("faultyFS");
        removeRootAfterClose = true;
    } else {
        if (! Files.isDirectory(root)) {
            throw new IllegalArgumentException("must be a directory.");
        }
        removeRootAfterClose = false;
    }
    this.root = root;
    delegate = root.getFileSystem();
    isOpen = true;
}
 
源代码11 项目: openjdk-jdk9   文件: FaultyFileSystem.java
FaultyFileSystem(Path root) throws IOException {
    if (root == null) {
        root = Files.createTempDirectory("faultyFS");
        removeRootAfterClose = true;
    } else {
        if (! Files.isDirectory(root)) {
            throw new IllegalArgumentException("must be a directory.");
        }
        removeRootAfterClose = false;
    }
    this.root = root;
    delegate = root.getFileSystem();
    isOpen = true;
}
 
源代码12 项目: LuckPerms   文件: FileWatcher.java
public FileWatcher(LuckPermsPlugin plugin, Path basePath) throws IOException {
    super(basePath.getFileSystem(), true);
    this.watchedLocations = Collections.synchronizedMap(new HashMap<>());
    this.basePath = basePath;

    super.registerRecursively(basePath);
    plugin.getBootstrap().getScheduler().executeAsync(super::runEventProcessingLoop);
}
 
@Override
public FileChannel newFileChannel(Path path,
		Set<? extends OpenOption> options, FileAttribute<?>... attrs)
		throws IOException {
	final BundleFileSystem fs = (BundleFileSystem) path.getFileSystem();
	FileChannel fc = origProvider(path).newFileChannel(fs.unwrap(path),
			options, attrs);
	return new BundleFileChannel(fc, path, options, attrs);
}
 
源代码14 项目: TencentKona-8   文件: JavacPathFileManager.java
private static Path resolve(Path base, String relativePath) {
    FileSystem fs = base.getFileSystem();
    Path rp = fs.getPath(relativePath.replace("/", fs.getSeparator()));
    return base.resolve(rp);
}
 
@Override
public boolean isSameFile(Path path, Path path2) throws IOException {
	BundleFileSystem fs = (BundleFileSystem) path.getFileSystem();
	return origProvider(path).isSameFile(fs.unwrap(path), fs.unwrap(path2));
}
 
源代码16 项目: mycore   文件: MCRDirectoryStream.java
private MCRPath checkFileSystem(Path path) {
    if (!(path.getFileSystem() instanceof MCRIFSFileSystem)) {
        throw new IllegalArgumentException(path + " is not from " + MCRIFSFileSystem.class.getSimpleName());
    }
    return MCRPath.toMCRPath(path);
}
 
private static Path resolve(Path base, String relativePath) {
    FileSystem fs = base.getFileSystem();
    Path rp = fs.getPath(relativePath.replace("/", fs.getSeparator()));
    return base.resolve(rp);
}
 
源代码18 项目: openjdk-8   文件: JavacPathFileManager.java
private static Path resolve(Path base, String relativePath) {
    FileSystem fs = base.getFileSystem();
    Path rp = fs.getPath(relativePath.replace("/", fs.getSeparator()));
    return base.resolve(rp);
}
 
@Override
public boolean isHidden(Path path) throws IOException {
	BundleFileSystem fs = (BundleFileSystem) path.getFileSystem();
	return origProvider(path).isHidden(fs.unwrap(path));
}
 
源代码20 项目: bt   文件: FileSystemStorage.java
public FileSystemStorage(Path rootDirectory) {
    this.rootDirectory = rootDirectory;
    this.pathNormalizer = new PathNormalizer(rootDirectory.getFileSystem());
}