本文整理了Java中java.nio.file.Files.readAttributes()
方法的一些代码示例,展示了Files.readAttributes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.readAttributes()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:readAttributes
暂无
代码示例来源:origin: google/guava
private BasicFileAttributes readAttributes() throws IOException {
return Files.readAttributes(
path,
BasicFileAttributes.class,
followLinks ? FOLLOW_LINKS : new LinkOption[] {NOFOLLOW_LINKS});
}
代码示例来源:origin: prestodb/presto
private BasicFileAttributes readAttributes() throws IOException {
return Files.readAttributes(
path,
BasicFileAttributes.class,
followLinks ? FOLLOW_LINKS : new LinkOption[] {NOFOLLOW_LINKS});
}
代码示例来源:origin: google/j2objc
private BasicFileAttributes readAttributes() throws IOException {
return Files.readAttributes(
path,
BasicFileAttributes.class,
followLinks ? FOLLOW_LINKS : new LinkOption[] {NOFOLLOW_LINKS});
}
代码示例来源:origin: wildfly/wildfly
private BasicFileAttributes readAttributes() throws IOException {
return Files.readAttributes(
path,
BasicFileAttributes.class,
followLinks ? FOLLOW_LINKS : new LinkOption[] {NOFOLLOW_LINKS});
}
代码示例来源:origin: chewiebug/GCViewer
private Optional<BasicFileAttributes> getFileAttributes(File file) {
try {
return Optional.of(Files.readAttributes(file.toPath(), BasicFileAttributes.class));
}
catch (IOException ex) {
logger.log(Level.WARNING, "Failed to read attributes of file " + file + ". Reason: " + ex.getMessage());
logger.log(Level.FINER, "Details: ", ex);
}
return Optional.empty();
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
public static long getLastModified( File file )
throws IOException
{
BasicFileAttributes basicFileAttributes = Files.readAttributes( file.toPath(), BasicFileAttributes.class );
return basicFileAttributes.lastModifiedTime().toMillis();
}
代码示例来源:origin: eclipse-vertx/vert.x
public FileProps perform() {
try {
Path target = vertx.resolveFile(path).toPath();
BasicFileAttributes attrs;
if (followLinks) {
attrs = Files.readAttributes(target, BasicFileAttributes.class);
} else {
attrs = Files.readAttributes(target, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
}
return new FilePropsImpl(attrs);
} catch (IOException e) {
throw new FileSystemException(e);
}
}
};
代码示例来源:origin: jenkinsci/jenkins
private static void makeWritable(@Nonnull Path path) throws IOException {
if (!Functions.isWindows()) {
try {
PosixFileAttributes attrs = Files.readAttributes(path, PosixFileAttributes.class);
Set<PosixFilePermission> newPermissions = attrs.permissions();
newPermissions.add(PosixFilePermission.OWNER_WRITE);
Files.setPosixFilePermissions(path, newPermissions);
} catch (NoSuchFileException ignored) {
return;
} catch (UnsupportedOperationException ignored) {
// PosixFileAttributes not supported, fall back to old IO.
}
}
/*
* We intentionally do not check the return code of setWritable, because if it
* is false we prefer to rethrow the exception thrown by Files.deleteIfExists,
* which will have a more useful message than something we make up here.
*/
path.toFile().setWritable(true);
}
代码示例来源:origin: spring-projects/spring-framework
Assert.notNull(src, "Source Path must not be null");
Assert.notNull(dest, "Destination Path must not be null");
BasicFileAttributes srcAttr = Files.readAttributes(src, BasicFileAttributes.class);
代码示例来源:origin: Alluxio/alluxio
/**
* Gets local file's owner.
*
* @param filePath the file path
* @return the owner of the local file
*/
public static String getLocalFileOwner(String filePath) throws IOException {
PosixFileAttributes attr =
Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class);
return attr.owner().getName();
}
代码示例来源:origin: Alluxio/alluxio
/**
* Gets local file's group.
*
* @param filePath the file path
* @return the group of the local file
*/
public static String getLocalFileGroup(String filePath) throws IOException {
PosixFileAttributes attr =
Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class);
return attr.group().getName();
}
代码示例来源:origin: SonarSource/sonarqube
private boolean isHidden(Path path) throws IOException {
if (SystemUtils.IS_OS_WINDOWS) {
try {
DosFileAttributes dosFileAttributes = Files.readAttributes(path, DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
return dosFileAttributes.isHidden();
} catch (UnsupportedOperationException e) {
return path.toFile().isHidden();
}
} else {
return Files.isHidden(path);
}
}
}
代码示例来源:origin: Alluxio/alluxio
/**
* Gets local file's permission mode.
*
* @param filePath the file path
* @return the file mode in short, e.g. 0777
*/
public static short getLocalFileMode(String filePath) throws IOException {
Set<PosixFilePermission> permission =
Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class).permissions();
return translatePosixPermissionToMode(permission);
}
代码示例来源:origin: Alluxio/alluxio
@Override
public UfsFileStatus getFileStatus(String path) throws IOException {
String tpath = stripPath(path);
File file = new File(tpath);
PosixFileAttributes attr =
Files.readAttributes(Paths.get(file.getPath()), PosixFileAttributes.class);
String contentHash =
UnderFileSystemUtils.approximateContentHash(file.length(), file.lastModified());
return new UfsFileStatus(path, contentHash, file.length(),
file.lastModified(), attr.owner().getName(), attr.group().getName(),
FileUtils.translatePosixPermissionToMode(attr.permissions()));
}
代码示例来源:origin: jenkinsci/jenkins
@Restricted(NoExternalUse.class)
public static boolean isSymlink(@Nonnull Path path) {
/*
* Windows Directory Junctions are effectively the same as Linux symlinks to directories.
* Unfortunately, the Java 7 NIO2 API function isSymbolicLink does not treat them as such.
* It thinks of them as normal directories. To use the NIO2 API & treat it like a symlink,
* you have to go through BasicFileAttributes and do the following check:
* isSymbolicLink() || isOther()
* The isOther() call will include Windows reparse points, of which a directory junction is.
* It also includes includes devices, but reading the attributes of a device with NIO fails
* or returns false for isOther(). (i.e. named pipes such as \\.\pipe\JenkinsTestPipe return
* false for isOther(), and drives such as \\.\PhysicalDrive0 throw an exception when
* calling readAttributes.
*/
try {
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
return attrs.isSymbolicLink() || (attrs instanceof DosFileAttributes && attrs.isOther());
} catch (IOException ignored) {
return false;
}
}
代码示例来源:origin: SonarSource/sonarqube
@CheckForNull
private static Object getFileKey(File fileInTempDir) throws IOException {
Path path = Paths.get(fileInTempDir.toURI());
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
return attrs.fileKey();
}
代码示例来源:origin: SonarSource/sonarqube
@CheckForNull
private static Object getFileKey(Path path) throws IOException {
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
return attrs.fileKey();
}
}
代码示例来源:origin: SonarSource/sonarqube
@CheckForNull
private static Object getFileKey(Path path) throws IOException {
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
return attrs.fileKey();
}
}
代码示例来源:origin: Alluxio/alluxio
@Override
public UfsDirectoryStatus getDirectoryStatus(String path) throws IOException {
String tpath = stripPath(path);
File file = new File(tpath);
PosixFileAttributes attr =
Files.readAttributes(Paths.get(file.getPath()), PosixFileAttributes.class);
return new UfsDirectoryStatus(path, attr.owner().getName(), attr.group().getName(),
FileUtils.translatePosixPermissionToMode(attr.permissions()), file.lastModified());
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testChownToOwnGroup() throws Exception {
// Not supported in WindowsFileSystemProvider
Assume.assumeFalse(Utils.isWindows());
String file1 = "some-file.dat";
createFileWithJunk(file1, 100);
String fullPath = testDir + pathSep + file1;
Path path = Paths.get(fullPath);
GroupPrincipal group = Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS).group();
vertx.fileSystem().chown(fullPath, null, group.getName(), ar -> {
deleteFile(file1);
assertTrue(ar.succeeded());
testComplete();
});
await();
}
内容来源于网络,如有侵权,请联系作者删除!