@Override public FileSystem getFileSystem() { return delegate.getFileSystem(); }
final Path p = Paths.get("/", "home", "text", "xyz.txt"); final PathMatcher filter = p.getFileSystem().getPathMatcher("glob:*.txt"); try (final Stream<Path> stream = Files.list(p)) { stream.filter(filter::matches) .forEach(System.out::println); }
/** * This implementation creates a FileSystemResource, applying the given path * relative to the path of the underlying file of this resource descriptor. * @see org.springframework.util.StringUtils#applyRelativePath(String, String) */ @Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return (this.file != null ? new FileSystemResource(pathToUse) : new FileSystemResource(this.filePath.getFileSystem(), pathToUse)); }
/** * This implementation creates a FileSystemResource, applying the given path * relative to the path of the underlying file of this resource descriptor. * @see org.springframework.util.StringUtils#applyRelativePath(String, String) */ @Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return (this.file != null ? new FileSystemResource(pathToUse) : new FileSystemResource(this.filePath.getFileSystem(), pathToUse)); }
} else { return path.getFileSystem().getPath(".");
private String pathToString(Path value, boolean nameOnly) { String pathAsString = (nameOnly && value.getNameCount() != 0 ? value.getFileName() : value).toString(); String separator = value.getFileSystem().getSeparator(); return !pathAsString.endsWith(separator) && Files.isDirectory(value) ? pathAsString + separator : pathAsString; }
public static String externalize(Path path) { if (path.getFileSystem().provider().getScheme().equals("file")) { return path.toString(); } else { return path.toUri().toString(); } }
@Nullable private JimfsPath checkPath(Path other) { if (checkNotNull(other) instanceof JimfsPath && other.getFileSystem().equals(getFileSystem())) { return (JimfsPath) other; } return null; } }
@Override public List<Resource> list() { final List<Resource> resources = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(file)) { for (Path child : stream) { resources.add(new PathResource(child, manager, path + file.getFileSystem().getSeparator() + child.getFileName().toString())); } } catch (IOException e) { throw new RuntimeException(e); } return resources; }
private void setExecutableIfAvailable(final String targetFileName) throws IOException { final Path targetPath = this.pluginBasePath.resolve(targetFileName); final FileSystem fileSystem = targetPath.getFileSystem(); if (fileSystem.supportedFileAttributeViews().contains("posix")) { // NTFS does not support PosixFilePermissions, for example. final Set<PosixFilePermission> permissions = new HashSet<PosixFilePermission>(Files.getPosixFilePermissions(targetPath)); permissions.add(PosixFilePermission.OWNER_EXECUTE); permissions.add(PosixFilePermission.GROUP_EXECUTE); permissions.add(PosixFilePermission.OTHERS_EXECUTE); Files.setPosixFilePermissions(targetPath, permissions); } }
@Override public void tearDown() throws IOException { rootDir.getFileSystem().close(); }
private void setExecutableIfAvailable(final String targetFileName) throws IOException { final Path targetPath = this.basePath.resolve(targetFileName); final FileSystem fileSystem = targetPath.getFileSystem(); if (fileSystem.supportedFileAttributeViews().contains("posix")) { // NTFS does not support PosixFilePermissions, for example. final Set<PosixFilePermission> permissions = new HashSet<PosixFilePermission>(Files.getPosixFilePermissions(targetPath)); permissions.add(PosixFilePermission.OWNER_EXECUTE); permissions.add(PosixFilePermission.GROUP_EXECUTE); permissions.add(PosixFilePermission.OTHERS_EXECUTE); Files.setPosixFilePermissions(targetPath, permissions); } }
public PathResourceManager setBase(final Path base) { if (base == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("base"); } this.fileSystem = base.getFileSystem(); String basePath = base.toAbsolutePath().toString(); if (!basePath.endsWith(fileSystem.getSeparator())) { basePath = basePath + fileSystem.getSeparator(); } this.base = basePath; return this; }
@Override public FileSystem newFileSystem(Path path, Map<String, ?> env) throws IOException { FileSystemProvider realProvider = path.getFileSystem().provider(); return realProvider.newFileSystem(path, env); }
private DirectoryStream<Path> directoryStream(Path dir) throws IOException { // create a matcher and return a filter that uses it. return dir.getFileSystem().provider().newDirectoryStream(dir, filter); } }
public static void main(String[] args) throws IOException { Configuration conf = new Configuration(); conf.addResource(new Path("/hadoop/projects/hadoop-1.0.4/conf/core-site.xml")); conf.addResource(new Path("/hadoop/projects/hadoop-1.0.4/conf/hdfs-site.xml")); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the file path..."); String filePath = br.readLine(); Path path = new Path(filePath); FileSystem fs = path.getFileSystem(conf); FSDataInputStream inputStream = fs.open(path); System.out.println(inputStream.available()); fs.close(); }
@Implementation protected final AssetFileDescriptor openFd(String fileName) throws IOException { Path path = findAssetFile(fileName); if (path.getFileSystem().provider().getScheme().equals("jar")) { path = getFileFromZip(path); } ParcelFileDescriptor parcelFileDescriptor = ParcelFileDescriptor.open(path.toFile(), ParcelFileDescriptor.MODE_READ_ONLY); return new AssetFileDescriptor(parcelFileDescriptor, 0, Files.size(path)); }
@Test public void testProviderEquals() { Path path1 = Paths.get(URI.create("gs://bucket/tuesday")); Path path2 = Paths.get(URI.create("gs://blood/wednesday")); Path path3 = Paths.get("tmp"); assertThat(path1.getFileSystem().provider()).isEqualTo(path2.getFileSystem().provider()); assertThat(path1.getFileSystem().provider()).isNotEqualTo(path3.getFileSystem().provider()); }
public static void setFilePermissions(Path filePath) throws IOException { if ("root".equalsIgnoreCase(ZaleniumConfiguration.getCurrentUser())) { UserPrincipal hostUid = filePath.getFileSystem() .getUserPrincipalLookupService().lookupPrincipalByName(ZaleniumConfiguration.getHostUid()); Files.setOwner(filePath, hostUid); GroupPrincipal hostGid = filePath.getFileSystem() .getUserPrincipalLookupService().lookupPrincipalByGroupName(ZaleniumConfiguration.getHostGid()); Files.getFileAttributeView(filePath, PosixFileAttributeView.class).setGroup(hostGid); } }
public Void perform() { try { Path target = vertx.resolveFile(path).toPath(); UserPrincipalLookupService service = target.getFileSystem().getUserPrincipalLookupService(); UserPrincipal userPrincipal = user == null ? null : service.lookupPrincipalByName(user); GroupPrincipal groupPrincipal = group == null ? null : service.lookupPrincipalByGroupName(group); if (groupPrincipal != null) { PosixFileAttributeView view = Files.getFileAttributeView(target, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); if (view == null) { throw new FileSystemException("Change group of file not supported"); } view.setGroup(groupPrincipal); } if (userPrincipal != null) { Files.setOwner(target, userPrincipal); } } catch (SecurityException e) { throw new FileSystemException("Accessed denied for chown on " + path); } catch (IOException e) { throw new FileSystemException(e); } return null; } };