当前位置: 首页>>代码示例>>Java>>正文


Java BasicFileAttributes.size方法代码示例

本文整理汇总了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;
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:21,代码来源:SearchFileVisitor.java

示例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;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:8,代码来源:DirectorySizeCalculator.java

示例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);
        }
    }
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:28,代码来源:ChunkReader.java

示例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);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:FileWatcher.java

示例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);
            }
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:41,代码来源:ImportableItem.java

示例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();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:15,代码来源:MoreFiles.java

示例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;
}
 
开发者ID:klask-io,项目名称:klask-io,代码行数:39,代码来源:FileSystemCrawler.java

示例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;
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:7,代码来源:Solution.java

示例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);
            }
        }
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:69,代码来源:FileWatcher.java


注:本文中的java.nio.file.attribute.BasicFileAttributes.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。