All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.jscancella.hash.internal.FileCountAndTotalSizeVistor Maven / Gradle / Ivy

Go to download

This is a software library intended to support the creation, manipulation, and validation of "bags" from the bagit specification. It currently supports version 0.93 through 1.0.

There is a newer version: 5.2
Show newest version
package com.github.jscancella.hash.internal;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ResourceBundle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Implements {@link SimpleFileVisitor} to calculate the PayloadOxum
 */
@SuppressWarnings({"PMD.BeanMembersShouldSerialize"})
public class FileCountAndTotalSizeVistor extends SimpleFileVisitor {
  private static final Logger logger = LoggerFactory.getLogger(FileCountAndTotalSizeVistor.class);
  private static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle");
  
  private long totalSize;
  private long count;

  @Override
  public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) throws IOException{
    count++;
    final long size = Files.size(path);
    logger.debug(messages.getString("file_size_in_bytes"), path, size);
    totalSize += size;
    
    return FileVisitResult.CONTINUE;
  }

  /**
   * @return the number of files in the path
   */
  public long getCount() {
    return count;
  }

  /**
   * @return the total file size in bytes in the path
   */
  public long getTotalSize() {
    return totalSize;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy