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

com.github.jscancella.conformance.internal.DataDirIsEmptyChecker 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.conformance.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.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * Checks for zero byte files and non zero byte files and records them for use in data directory must be empty bagit profile
 */
public class DataDirIsEmptyChecker extends SimpleFileVisitor {
  private final Set nonZeroByteFiles;
  private final Set zeroByteFiles;
  
  /**
   * Checks for zero byte files and non zero byte files and records them for use in data directory must be empty bagit profile
   */
  public DataDirIsEmptyChecker() {
    super();
    this.nonZeroByteFiles = new HashSet<>();
    this.zeroByteFiles = new HashSet<>();
  }

  @Override
  public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) throws IOException{
    if(Files.size(path)>0) {
      this.nonZeroByteFiles.add(path);
    }
    else {
      this.zeroByteFiles.add(path);
    }
    
    return FileVisitResult.CONTINUE;
  }
  
  /**
   * @return the nonZeroByteFiles
   */
  public Set getNonZeroByteFiles() {
    return Collections.unmodifiableSet(nonZeroByteFiles);
  }

  /**
   * @return the zeroByteFiles
   */
  public Set getZeroByteFiles() {
    return Collections.unmodifiableSet(zeroByteFiles);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy