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

com.github.jscancella.hash.PayloadOxumGenerator 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;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import com.github.jscancella.hash.internal.FileCountAndTotalSizeVistor;

/**
 * a singleton used to generate the payload oxum for a bag
 */
public enum PayloadOxumGenerator {;//using enum to enforce singleton

  /**
   * Calculate the total file and byte count of the files in the payload directory
   * 
   * @param dataDir the directory to calculate the payload-oxum
   * 
   * @return the string representation of the payload-oxum value
   * 
   * @throws IOException if there is an error reading any of the files
   */
  public static String generatePayloadOxum(final Path dataDir) throws IOException{
    final FileCountAndTotalSizeVistor visitor = new FileCountAndTotalSizeVistor();
    
    Files.walkFileTree(dataDir, visitor);
    
    return visitor.getTotalSize() + "." + visitor.getCount();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy