java.nio.file.Path.getFileSystem()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(330)

本文整理了Java中java.nio.file.Path.getFileSystem()方法的一些代码示例,展示了Path.getFileSystem()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.getFileSystem()方法的具体详情如下:
包路径:java.nio.file.Path
类名称:Path
方法名:getFileSystem

Path.getFileSystem介绍

暂无

代码示例

代码示例来源:origin: apache/groovy

@Override
public FileSystem getFileSystem() {
  return delegate.getFileSystem();
}

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * 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));
}

代码示例来源:origin: org.springframework/spring-core

/**
 * 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));
}

代码示例来源:origin: google/guava

} else {
 return path.getFileSystem().getPath(".");

代码示例来源:origin: MovingBlocks/Terasology

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;
}

代码示例来源:origin: robolectric/robolectric

public static String externalize(Path path) {
 if (path.getFileSystem().provider().getScheme().equals("file")) {
  return path.toString();
 } else {
  return path.toUri().toString();
 }
}

代码示例来源:origin: google/jimfs

@Nullable
 private JimfsPath checkPath(Path other) {
  if (checkNotNull(other) instanceof JimfsPath && other.getFileSystem().equals(getFileSystem())) {
   return (JimfsPath) other;
  }
  return null;
 }
}

代码示例来源:origin: wildfly/wildfly

@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;
}

代码示例来源:origin: embulk/embulk

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);
  }
}

代码示例来源:origin: google/guava

@Override
public void tearDown() throws IOException {
 rootDir.getFileSystem().close();
}

代码示例来源:origin: embulk/embulk

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);
  }
}

代码示例来源:origin: wildfly/wildfly

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;
}

代码示例来源:origin: google/jimfs

@Override
public FileSystem newFileSystem(Path path, Map<String, ?> env) throws IOException {
 FileSystemProvider realProvider = path.getFileSystem().provider();
 return realProvider.newFileSystem(path, env);
}

代码示例来源:origin: blynkkk/blynk-server

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);
  }
}

代码示例来源:origin: stackoverflow.com

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();
}

代码示例来源:origin: robolectric/robolectric

@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));
}

代码示例来源:origin: googleapis/google-cloud-java

@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());
}

代码示例来源:origin: zalando/zalenium

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);
  }
}

代码示例来源:origin: eclipse-vertx/vert.x

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;
 }
};

相关文章