热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

java.nio.file.attribute.BasicFileAttributes.size()方法的使用及代码示例

本文整理了Java中java.nio.file.attribute.BasicFileAttributes.size()方法的一些代码示例,展示了Basic

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

BasicFileAttributes.size介绍

暂无

代码示例

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

/** {@inheritDoc} */
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
size += attrs.size();
return FileVisitResult.CONTINUE;
}

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

@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
s.addAndGet(attrs.size());
return FileVisitResult.CONTINUE;
}

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

@Override
public long size() throws IOException {
BasicFileAttributes attrs = readAttributes();
// Don't return a size for directories or symbolic links; their sizes are implementation
// specific and they can't be read as bytes using the read methods anyway.
if (attrs.isDirectory()) {
throw new IOException("can't read: is a directory");
} else if (attrs.isSymbolicLink()) {
throw new IOException("can't read: is a symbolic link");
}
return attrs.size();
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
// size is specified on regular files only
// https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/BasicFileAttributes.html#size--
if (attrs.isRegularFile()) {
size += attrs.size();
}
return FileVisitResult.CONTINUE;
}
}

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

@Override
public Optional sizeIfKnown() {
BasicFileAttributes attrs;
try {
attrs = readAttributes();
} catch (IOException e) {
// Failed to get attributes; we don't know the size.
return Optional.absent();
}
// Don't return a size for directories or symbolic links; their sizes are implementation
// specific and they can't be read as bytes using the read methods anyway.
if (attrs.isDirectory() || attrs.isSymbolicLink()) {
return Optional.absent();
}
return Optional.of(attrs.size());
}

代码示例来源:origin: prestodb/presto

@Override
public long size() throws IOException {
BasicFileAttributes attrs = readAttributes();
// Don't return a size for directories or symbolic links; their sizes are implementation
// specific and they can't be read as bytes using the read methods anyway.
if (attrs.isDirectory()) {
throw new IOException("can't read: is a directory");
} else if (attrs.isSymbolicLink()) {
throw new IOException("can't read: is a symbolic link");
}
return attrs.size();
}

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

@Override
public long size() throws IOException {
BasicFileAttributes attrs = readAttributes();
// Don't return a size for directories or symbolic links; their sizes are implementation
// specific and they can't be read as bytes using the read methods anyway.
if (attrs.isDirectory()) {
throw new IOException("can't read: is a directory");
} else if (attrs.isSymbolicLink()) {
throw new IOException("can't read: is a symbolic link");
}
return attrs.size();
}

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

@Override
public Optional sizeIfKnown() {
BasicFileAttributes attrs;
try {
attrs = readAttributes();
} catch (IOException e) {
// Failed to get attributes; we don't know the size.
return Optional.absent();
}
// Don't return a size for directories or symbolic links; their sizes are implementation
// specific and they can't be read as bytes using the read methods anyway.
if (attrs.isDirectory() || attrs.isSymbolicLink()) {
return Optional.absent();
}
return Optional.of(attrs.size());
}

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

public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
size.addAndGet(attrs.size());
return FileVisitResult.CONTINUE;

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

@Override
public long size() throws IOException {
BasicFileAttributes attrs = readAttributes();
// Don't return a size for directories or symbolic links; their sizes are implementation
// specific and they can't be read as bytes using the read methods anyway.
if (attrs.isDirectory()) {
throw new IOException("can't read: is a directory");
} else if (attrs.isSymbolicLink()) {
throw new IOException("can't read: is a symbolic link");
}
return attrs.size();
}

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

@Override
public Optional sizeIfKnown() {
BasicFileAttributes attrs;
try {
attrs = readAttributes();
} catch (IOException e) {
// Failed to get attributes; we don't know the size.
return Optional.absent();
}
// Don't return a size for directories or symbolic links; their sizes are implementation
// specific and they can't be read as bytes using the read methods anyway.
if (attrs.isDirectory() || attrs.isSymbolicLink()) {
return Optional.absent();
}
return Optional.of(attrs.size());
}

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

@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
if (attrs.isDirectory()) {
return FileVisitResult.CONTINUE;
}
final long lastModTime = getLastModTime(file);
if (lastModTime try {
Files.deleteIfExists(file);
containerState.decrementArchiveCount();
LOG.debug("Deleted archived ContentClaim with ID {} from Container {} because it was older than the configured max archival duration",
file.toFile().getName(), containerName);
} catch (final IOException ioe) {
LOG.warn("Failed to remove archived ContentClaim with ID {} from Container {} due to {}", file.toFile().getName(), containerName, ioe.toString());
if (LOG.isDebugEnabled()) {
LOG.warn("", ioe);
}
}
} else if (usableSpace notYetExceedingThreshold.add(new ArchiveInfo(container, file, attrs.size(), lastModTime));
}
return FileVisitResult.CONTINUE;
}
});

代码示例来源:origin: line/armeria

@Override
public HttpFileAttributes readAttributes() throws IOException {
if (!Files.exists(path)) {
return null;
}
try {
final BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
if (attrs.isRegularFile()) {
return new HttpFileAttributes(attrs.size(), attrs.lastModifiedTime().toMillis());
}
} catch (NoSuchFileException e) {
// Non-existent file.
}
return null;
}

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

public FilePropsImpl(BasicFileAttributes attrs) {
creatiOnTime= attrs.creationTime().toMillis();
lastModifiedTime = attrs.lastModifiedTime().toMillis();
lastAccessTime = attrs.lastAccessTime().toMillis();
isDirectory = attrs.isDirectory();
isOther = attrs.isOther();
isRegularFile = attrs.isRegularFile();
isSymbolicLink = attrs.isSymbolicLink();
size = attrs.size();
}

代码示例来源:origin: spotify/docker-client

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
final Path relativePath = root.relativize(file);
if (exclude(ignoreMatchers, relativePath)) {
return FileVisitResult.CONTINUE;
}
final TarArchiveEntry entry = new TarArchiveEntry(file.toFile());
entry.setName(relativePath.toString());
entry.setMode(getFileMode(file));
entry.setSize(attrs.size());
tarStream.putArchiveEntry(entry);
Files.copy(file, tarStream);
tarStream.closeArchiveEntry();
return FileVisitResult.CONTINUE;
}

代码示例来源:origin: Netflix/Priam

private static FileUploadResult getFileUploadResult(
String keyspaceName, String columnFamilyName, Path file) throws Exception {
BasicFileAttributes fileAttributes = Files.readAttributes(file, BasicFileAttributes.class);
return new FileUploadResult(
file,
keyspaceName,
columnFamilyName,
fileAttributes.lastModifiedTime().toInstant(),
fileAttributes.creationTime().toInstant(),
fileAttributes.size());
}

代码示例来源:origin: prestodb/presto

@Override
public Optional sizeIfKnown() {
BasicFileAttributes attrs;
try {
attrs = readAttributes();
} catch (IOException e) {
// Failed to get attributes; we don't know the size.
return Optional.absent();
}
// Don't return a size for directories or symbolic links; their sizes are implementation
// specific and they can't be read as bytes using the read methods anyway.
if (attrs.isDirectory() || attrs.isSymbolicLink()) {
return Optional.absent();
}
return Optional.of(attrs.size());
}

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

if (minSize > attributes.size()) {
return false;
if (maxSize != null && maxSize return false;

代码示例来源:origin: Graylog2/graylog2-server

/**
* Create a file info for the given path.
*
* @param path the path must exist, otherwise an IllegalArgumentException is thrown
* @return the file info object
*/
@NotNull
public static FileInfo forPath(Path path) {
try {
final BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class);
return FileInfo.builder()
.path(path)
.key(attributes.fileKey())
.size(attributes.size())
.modificationTime(attributes.lastModifiedTime())
.build();
} catch (Exception e) {
LOG.error("Couldn't get file info for path: {}", path, e);
return EMPTY_FILE_INFO.toBuilder().path(path).build();
}
}

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

.fullPathFileName(file.getAbsolutePath())
.lastModifiedTime(attributes.lastModifiedTime().toMillis())
.size(attributes.size())
.build();

推荐阅读
author-avatar
shengxin11
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有