Java Code Examples for java.nio.file.Path#getFileSystem()

The following examples show how to use java.nio.file.Path#getFileSystem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppleSdkDiscoveryTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 2
Source File: BundleFileSystemProvider.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
@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());
		}
	};
}
 
Example 3
Source File: BundleFileSystemProvider.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 5
Source File: BundleFileSystemProvider.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: JimfsFileSystemProvider.java    From jimfs with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: FaultyFileSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: BundleFileSystemProvider.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: FaultyFileSystem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: Locations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
    }
 
Example 11
Source File: FaultyFileSystem.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: FaultyFileSystem.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: FileWatcher.java    From LuckPerms with MIT License 5 votes vote down vote up
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);
}
 
Example 14
Source File: JavacPathFileManager.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static Path resolve(Path base, String relativePath) {
    FileSystem fs = base.getFileSystem();
    Path rp = fs.getPath(relativePath.replace("/", fs.getSeparator()));
    return base.resolve(rp);
}
 
Example 15
Source File: FileSystemStorage.java    From bt with Apache License 2.0 4 votes vote down vote up
public FileSystemStorage(Path rootDirectory) {
    this.rootDirectory = rootDirectory;
    this.pathNormalizer = new PathNormalizer(rootDirectory.getFileSystem());
}
 
Example 16
Source File: BundleFileSystemProvider.java    From incubator-taverna-language with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isHidden(Path path) throws IOException {
	BundleFileSystem fs = (BundleFileSystem) path.getFileSystem();
	return origProvider(path).isHidden(fs.unwrap(path));
}
 
Example 17
Source File: JavacPathFileManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static Path resolve(Path base, String relativePath) {
    FileSystem fs = base.getFileSystem();
    Path rp = fs.getPath(relativePath.replace("/", fs.getSeparator()));
    return base.resolve(rp);
}
 
Example 18
Source File: MCRDirectoryStream.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
private MCRPath checkFileSystem(Path path) {
    if (!(path.getFileSystem() instanceof MCRIFSFileSystem)) {
        throw new IllegalArgumentException(path + " is not from " + MCRIFSFileSystem.class.getSimpleName());
    }
    return MCRPath.toMCRPath(path);
}
 
Example 19
Source File: BundleFileSystemProvider.java    From incubator-taverna-language with Apache License 2.0 4 votes vote down vote up
@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));
}
 
Example 20
Source File: JavacPathFileManager.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static Path resolve(Path base, String relativePath) {
    FileSystem fs = base.getFileSystem();
    Path rp = fs.getPath(relativePath.replace("/", fs.getSeparator()));
    return base.resolve(rp);
}