當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。