Java Code Examples for java.nio.file.attribute.UserDefinedFileAttributeView#list()

The following examples show how to use java.nio.file.attribute.UserDefinedFileAttributeView#list() . 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: FileAttributes.java    From yfs with Apache License 2.0 5 votes vote down vote up
public static Map<String, String> getAllXattr(String fullPath) throws IOException {
    Map<String, String> values = Maps.newHashMap();
    UserDefinedFileAttributeView view = getAttributeView(fullPath);
    for (String name : view.list()) {
        String value = getAttrValue(view, name);
        values.put(name, value);
    }
    return values;
}
 
Example 2
Source File: UserExtendedAttributes.java    From yfs with Apache License 2.0 5 votes vote down vote up
/**
 * List all user extended attributes and their related values for the given
 * file.
 *
 * @throws IOException when the user extended attribute information could
 * not be read
 */
private static void dumpAllXattr(String file) {
    UserDefinedFileAttributeView view = getAttributeView(file);

    System.out.printf("# file: %s%n", file);
    try {
        for (String name : view.list()) {
            String value = getAttrValue(view, name);
            System.out.printf("user.%s=\"%s\"%n", name, value);
        }
    } catch (IOException ex) {
        System.out.printf("failed to get the extended attribute informations from %s%n", file);
    }
}
 
Example 3
Source File: SingularityUploader.java    From Singularity with Apache License 2.0 5 votes vote down vote up
UploaderFileAttributes getFileAttributes(Path file) {
  Set<String> supportedViews = FileSystems.getDefault().supportedFileAttributeViews();
  LOG.trace("Supported attribute views are {}", supportedViews);
  if (supportedViews.contains("user")) {
    try {
      UserDefinedFileAttributeView view = Files.getFileAttributeView(
        file,
        UserDefinedFileAttributeView.class
      );
      List<String> attributes = view.list();
      LOG.debug("Found file attributes {} for file {}", attributes, file);
      Optional<Long> maybeStartTime = readFileAttributeAsLong(
        file,
        LOG_START_TIME_ATTR,
        view,
        attributes
      );
      Optional<Long> maybeEndTime = readFileAttributeAsLong(
        file,
        LOG_END_TIME_ATTR,
        view,
        attributes
      );
      return new UploaderFileAttributes(maybeStartTime, maybeEndTime);
    } catch (Exception e) {
      LOG.error("Could not get extra file metadata for {}", file, e);
    }
  }
  return new UploaderFileAttributes(Optional.empty(), Optional.empty());
}