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

x33g5p2x  于2022-01-17 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(199)

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

Files.getAttribute介绍

暂无

代码示例

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

private long getInode(File file) throws IOException {
 long inode = (long) Files.getAttribute(file.toPath(), "unix:ino");
 return inode;
}

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

private static boolean isPipe(FileSystem fs, FileStatus file) {
 if (fs instanceof DistributedFileSystem) {
  return false; // Shortcut for HDFS.
 }
 int mode = 0;
 Object pathToLog = file.getPath();
 try {
  java.nio.file.Path realPath = Paths.get(file.getPath().toUri());
  pathToLog = realPath;
  mode = (Integer)Files.getAttribute(realPath, "unix:mode");
 } catch (FileSystemNotFoundException t) {
  return false; // Probably not a local filesystem; no need to check.
 } catch (UnsupportedOperationException | IOException
   | SecurityException | IllegalArgumentException t) {
  LOG.info("Failed to check mode for " + pathToLog + ": "
   + t.getMessage() + " (" + t.getClass() + ")");
  return false;
 }
 return (mode & S_IFIFO) != 0;
}

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

private static boolean isPipe(FileSystem fs, FileStatus file) {
 if (fs instanceof DistributedFileSystem) {
  return false; // Shortcut for HDFS.
 }
 int mode = 0;
 Object pathToLog = file.getPath();
 try {
  java.nio.file.Path realPath = Paths.get(file.getPath().toUri());
  pathToLog = realPath;
  mode = (Integer)Files.getAttribute(realPath, "unix:mode");
 } catch (FileSystemNotFoundException t) {
  return false; // Probably not a local filesystem; no need to check.
 } catch (UnsupportedOperationException | IOException
   | SecurityException | IllegalArgumentException t) {
  LOG.info("Failed to check mode for " + pathToLog + ": "
   + t.getMessage() + " (" + t.getClass() + ")");
  return false;
 }
 return (mode & S_IFIFO) != 0;
}

代码示例来源:origin: jphp-group/jphp

public static Memory filegroup(Environment env, TraceInfo trace, String path) {
  Path file = Paths.get(path);
  try {
    int attribute = (int) Files.getAttribute(file, "unix:gid");
    return LongMemory.valueOf(attribute);
  } catch (IOException | SecurityException e) {
    env.warning(trace, e.getMessage());
    return Memory.FALSE;
  } catch (UnsupportedOperationException e) {
    return Memory.FALSE;
  }
}

代码示例来源:origin: jphp-group/jphp

public static Memory fileowner(Environment env, TraceInfo trace, String path) {
  Path file = Paths.get(path);
  try {
    int attribute = (int) Files.getAttribute(file, "unix:uid");
    return LongMemory.valueOf(attribute);
  } catch (IOException | SecurityException e) {
    env.warning(trace, e.getMessage());
    return Memory.FALSE;
  } catch (UnsupportedOperationException e) {
    return Memory.FALSE;
  }
}

代码示例来源:origin: jphp-group/jphp

public static Memory fileperms(Environment env, TraceInfo trace, String path) {
  Path file = Paths.get(path);
  try {
    int attribute = (int) Files.getAttribute(file, "unix:mode");
    return LongMemory.valueOf(attribute);
  } catch (IOException | SecurityException e) {
    env.warning(trace, e.getMessage());
    return Memory.FALSE;
  } catch (UnsupportedOperationException e) {
    return Memory.FALSE;
  }
}

代码示例来源:origin: testcontainers/testcontainers-java

private int getUnixFileMode(final String pathAsString) {
  final Path path = Paths.get(pathAsString);
  if (this.forcedFileMode != null) {
    return this.getModeValue(path);
  }
  try {
    return (int) Files.getAttribute(path, "unix:mode");
  } catch (IOException | UnsupportedOperationException e) {
    // fallback for non-posix environments
    int mode = DEFAULT_FILE_MODE;
    if (Files.isDirectory(path)) {
      mode = DEFAULT_DIR_MODE;
    } else if (Files.isExecutable(path)) {
      mode |= 0111; // equiv to +x for user/group/others
    }
    return mode;
  }
}

代码示例来源:origin: testcontainers/testcontainers-java

@NotNull
protected DockerClientConfig tryConfiguration(String dockerHost) {
  Path dockerSocketFile = Paths.get(DOCKER_SOCK_PATH);
  Integer mode;
  try {
    mode = (Integer) Files.getAttribute(dockerSocketFile, "unix:mode");
  } catch (IOException e) {
    throw new InvalidConfigurationException("Could not find unix domain socket", e);
  }
  if ((mode & 0xc000) != SOCKET_FILE_MODE_MASK) {
    throw new InvalidConfigurationException("Found docker unix domain socket but file mode was not as expected (expected: srwxr-xr-x). This problem is possibly due to occurrence of this issue in the past: https://github.com/docker/docker/issues/13121");
  }
  config = DefaultDockerClientConfig.createDefaultConfigBuilder()
      .withDockerHost(dockerHost)
      .withDockerTlsVerify(false)
      .build();
  client = getClientForConfig(config);
  final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT));
  ping(client, timeout);
  return config;
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

final Path path = Paths.get(DIR, "rollingtest.log");
if (Files.exists(path) && createOnDemand) {
  Assert.fail(String.format("Unexpected file: %s (%s bytes)", path, Files.getAttribute(path, "size")));

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

Paths.get(lock.getAbsolutePath() + ".lnk"), //$NON-NLS-1$
    lockPath);
Integer nlink = (Integer) (Files.getAttribute(lockPath,
    "unix:nlink")); //$NON-NLS-1$
if (nlink > 2) {

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

try {
  link = Files.createLink(Paths.get(uniqueLinkPath(file)), path);
  Integer nlink = (Integer) (Files.getAttribute(path,
      "unix:nlink")); //$NON-NLS-1$
  if (nlink.intValue() > 2) {

代码示例来源:origin: opendedup/sdfs

public int getMode() throws IOException {
  if (mode == -1) {
    Path p = Paths.get(this.path);
    this.mode = (Integer) Files.getAttribute(p, "unix:mode");
  }
  return this.mode;
}

代码示例来源:origin: opendedup/sdfs

/**
 * 
 * @return returns the group owner id
 * @throws IOException
 */
public int getGroup_id() throws IOException {
  if (group_id == -1) {
    Path p = Paths.get(this.path);
    this.group_id = (Integer) Files.getAttribute(p, "unix:gid");
  }
  return group_id;
}

代码示例来源:origin: opendedup/sdfs

/**
 * 
 * @return the file owner id
 * @throws IOException
 */
public int getOwner_id() throws IOException {
  if (owner_id == -1) {
    Path p = Paths.get(this.path);
    this.owner_id = (Integer) Files.getAttribute(p, "unix:uid");
  }
  return owner_id;
}

代码示例来源:origin: ICIJ/extract

@Override
  public boolean matches(final Path path) {
    try {
      final Boolean hidden = (Boolean) Files.getAttribute(path, "dos:hidden");

      return hidden != null && Boolean.TRUE.equals(hidden); 
    } catch (IOException e) {
      return false;
    }
  }
}

代码示例来源:origin: org.apache.flume.flume-ng-sources/flume-taildir-source

private long getInode(File file) throws IOException {
 long inode = (long) Files.getAttribute(file.toPath(), "unix:ino");
 return inode;
}

代码示例来源:origin: io.permazen/permazen-kv-raft

/**
 * Get the length of a file.
 *
 * @param file file to measure
 * @return file length
 * @throws IOException if an I/O error occurs
 * @throws IllegalArgumentException if {@code file} is null
 */
public static long getLength(final File file) throws IOException {
  Preconditions.checkArgument(file != null, "null file");
  return (Long)Files.getAttribute(file.toPath(), "size");
}

代码示例来源:origin: de.pfabulist.lindwurm/niotest

@Test
@Category( Attributes.class )
public void testGetUnsupportedAttributeThrows() throws IOException {
  assertThatThrownBy( () -> Files.getAttribute( fileTA(), "whoaa:freeze" ) ).isInstanceOf( UnsupportedOperationException.class );
}

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

@Test(expected = UnsupportedOperationException.class)
public void getAttribute() throws IOException {
  Files.getAttribute(fs.getPath("file"), "basic", (LinkOption) null);
}

代码示例来源:origin: de.pfabulist.lindwurm/niotest

@Test
@Category( Attributes.class )
@SuppressWarnings( "PMD.JUnitTestsShouldIncludeAssert" )
public void testGetUnsupportedAttributeThrows2() throws IOException {
  description.getAttributeDescriptions().forEach(
      ad -> assertThatThrownBy( () -> Files.getAttribute( getFile(), ad.getName() + ":areallystupidname" ) ).
          isInstanceOf( IllegalArgumentException.class ) );
}

相关文章

微信公众号

最新文章

更多