本文整理匯總了Java中java.nio.file.attribute.BasicFileAttributes.size方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicFileAttributes.size方法的具體用法?Java BasicFileAttributes.size怎麽用?Java BasicFileAttributes.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.file.attribute.BasicFileAttributes
的用法示例。
在下文中一共展示了BasicFileAttributes.size方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visitFile
import java.nio.file.attribute.BasicFileAttributes; //導入方法依賴的package包/類
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (!attrs.isRegularFile()) return CONTINUE;
if (partOfNameCheck && file.getFileName().toString().indexOf(this.partOfName) == -1)
return CONTINUE;
if (minSizeCheck && attrs.size() < minSize)
return CONTINUE;
if (maxSizeCheck && attrs.size() > maxSize)
return CONTINUE;
if (partOfContentCheck && new String(Files.readAllBytes(file)).indexOf(partOfContent) == -1)
return CONTINUE;
foundFiles.add(file);
return CONTINUE;
}
示例2: visitFile
import java.nio.file.attribute.BasicFileAttributes; //導入方法依賴的package包/類
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
{
if (isAcceptable(file))
size += attrs.size();
return FileVisitResult.CONTINUE;
}
示例3: ChunkReader
import java.nio.file.attribute.BasicFileAttributes; //導入方法依賴的package包/類
public ChunkReader(Input fileInput,
Path path,
AsynchronousFileChannel fileChannel,
BlockingQueue<FileChunk> chunks,
int initialChunkSize,
FileInput.InitialReadPosition initialReadPosition,
ChunkReaderScheduler chunkReaderScheduler) {
this.fileInput = fileInput;
this.path = path;
this.fileChannel = fileChannel;
this.chunks = chunks;
this.initialChunkSize = initialChunkSize;
this.chunkReaderScheduler = chunkReaderScheduler;
Preconditions.checkArgument(initialChunkSize > 0, "Chunk size must be positive");
if (fileChannel.isOpen()) {
try {
final BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
fileKey = attr.fileKey();
if (initialReadPosition == FileInput.InitialReadPosition.END) {
position = attr.size();
}
} catch (IOException e) {
log.error("Cannot access file metadata", e);
}
}
}
示例4: init
import java.nio.file.attribute.BasicFileAttributes; //導入方法依賴的package包/類
private void init(boolean initial) throws IOException {
exists = Files.exists(file);
if (exists) {
BasicFileAttributes attributes = Files.readAttributes(file, BasicFileAttributes.class);
isDirectory = attributes.isDirectory();
if (isDirectory) {
onDirectoryCreated(initial);
} else {
length = attributes.size();
lastModified = attributes.lastModifiedTime().toMillis();
onFileCreated(initial);
}
}
}
示例5: setContentFile
import java.nio.file.attribute.BasicFileAttributes; //導入方法依賴的package包/類
public final void setContentFile(final Path contentFile)
{
this.contentFile = contentFile;
if (contentFile != null)
{
// stat the file, to find out a few key details
contentFileExists = Files.exists(contentFile, LinkOption.NOFOLLOW_LINKS);
if (contentFileExists)
{
try
{
BasicFileAttributes attrs = Files.readAttributes(contentFile, BasicFileAttributes.class);
contentFileIsReadable = Files.isReadable(contentFile);
contentFileSize = attrs.size();
contentFileModified = new Date(attrs.lastModifiedTime().toMillis());
contentFileCreated = new Date(attrs.creationTime().toMillis());
if (Files.isRegularFile(contentFile, LinkOption.NOFOLLOW_LINKS))
{
contentFileType = FileType.FILE;
}
else if (Files.isDirectory(contentFile, LinkOption.NOFOLLOW_LINKS))
{
contentFileType = FileType.DIRECTORY;
}
else
{
contentFileType = FileType.OTHER;
}
}
catch (IOException e)
{
logger.error("Attributes for file '" + FileUtils.getFileName(contentFile) + "' could not be read.", e);
}
}
}
}
示例6: size
import java.nio.file.attribute.BasicFileAttributes; //導入方法依賴的package包/類
@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();
}
示例7: constructFile
import java.nio.file.attribute.BasicFileAttributes; //導入方法依賴的package包/類
/**
* Construct a {@link File} with a version and readContent
*
* @param name
* @param extension
* @param path
* @return
* @throws IOException
*/
private File constructFile(String name, String extension, Path path) throws IOException {
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
long size = attrs.size();
String content = null;
if ((!readableExtensionSet.contains(extension) && !"".equals(extension))
|| size > Constants.MAX_SIZE_FOR_INDEXING_ONE_FILE) {
log.trace("parsing only name on file : {}", path);
} else {
content = readContent(path);
}
File fichier = new File(
UUID.randomUUID().toString(),
name,
extension,
path.toString(),
null,
content,
null,
size
);
setVersionAndProject(fichier, path.toString());
fichier.setCreatedDate(attrs.creationTime().toInstant().atZone(ZoneId.systemDefault()));
fichier.setLastModifiedDate(attrs.lastModifiedTime().toInstant().atZone(ZoneId.systemDefault()));
return fichier;
}
示例8: visitFile
import java.nio.file.attribute.BasicFileAttributes; //導入方法依賴的package包/類
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
totalFiles += 1;
totalSize = totalSize + attrs.size();
return CONTINUE;
}
示例9: checkAndNotify
import java.nio.file.attribute.BasicFileAttributes; //導入方法依賴的package包/類
public void checkAndNotify() throws IOException {
boolean prevExists = exists;
boolean prevIsDirectory = isDirectory;
long prevLength = length;
long prevLastModified = lastModified;
exists = Files.exists(file);
// TODO we might use the new NIO2 API to get real notification?
if (exists) {
BasicFileAttributes attributes = Files.readAttributes(file, BasicFileAttributes.class);
isDirectory = attributes.isDirectory();
if (isDirectory) {
length = 0;
lastModified = 0;
} else {
length = attributes.size();
lastModified = attributes.lastModifiedTime().toMillis();
}
} else {
isDirectory = false;
length = 0;
lastModified = 0;
}
// Perform notifications and update children for the current file
if (prevExists) {
if (exists) {
if (isDirectory) {
if (prevIsDirectory) {
// Remained a directory
updateChildren();
} else {
// File replaced by directory
onFileDeleted();
onDirectoryCreated(false);
}
} else {
if (prevIsDirectory) {
// Directory replaced by file
onDirectoryDeleted();
onFileCreated(false);
} else {
// Remained file
if (prevLastModified != lastModified || prevLength != length) {
onFileChanged();
}
}
}
} else {
// Deleted
if (prevIsDirectory) {
onDirectoryDeleted();
} else {
onFileDeleted();
}
}
} else {
// Created
if (exists) {
if (isDirectory) {
onDirectoryCreated(false);
} else {
onFileCreated(false);
}
}
}
}