Class PathUtils

java.lang.Object
nl.knaw.dans.bagit.util.PathUtils

public final class PathUtils extends Object
Convenience class for dealing with various path issues
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
     
    private static final String
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    as per https://github.com/jkunze/bagitspec/commit/152d42f6298b31a4916ea3f8f644ca4490494070 decode percent encoded filenames
    static String
    as per https://github.com/jkunze/bagitspec/commit/152d42f6298b31a4916ea3f8f644ca4490494070 encode any new lines or carriage returns
    static String
    Calculate the total file and byte count of the files in the payload directory
    static Path
    With bagit version 2.0 (.bagit) bagit specific files are no longer at the bag root directory.
    static Path
    getBagitDir(Version version, Path bagRoot)
    With bagit version 2.0 (.bagit) bagit specific files are no longer at the bag root directory.
    static Path
    With bagit version 2.0 (.bagit) payload files are no longer in the "data" directory.
    static Path
    getDataDir(Version version, Path output)
    With bagit version 2.0 (.bagit) payload files are no longer in the "data" directory.
    static String
    Needed to get rid of findbugs "dodgy code warnings" in regards to getting the filename of a path as a string
    static boolean
    isHidden(Path path)
    Due to the way that windows handles hidden files vs.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • PathUtils

      private PathUtils()
  • Method Details

    • getFilename

      public static String getFilename(Path path)
      Needed to get rid of findbugs "dodgy code warnings" in regards to getting the filename of a path as a string
      Parameters:
      path - the path that you which to get the filename as a string
      Returns:
      the filename or an empty string
    • decodeFilname

      public static String decodeFilname(String encoded)
      as per https://github.com/jkunze/bagitspec/commit/152d42f6298b31a4916ea3f8f644ca4490494070 decode percent encoded filenames
      Parameters:
      encoded - the encoded filename
      Returns:
      the decoded filename
    • encodeFilename

      public static String encodeFilename(Path path)
      as per https://github.com/jkunze/bagitspec/commit/152d42f6298b31a4916ea3f8f644ca4490494070 encode any new lines or carriage returns
      Parameters:
      path - the path to encode
      Returns:
      the encoded filename
    • isHidden

      public static boolean isHidden(Path path) throws IOException
      Due to the way that windows handles hidden files vs. *nix we use this method to determine if a file or folder is really hidden
      Parameters:
      path - the file or folder to check if hidden
      Returns:
      if the file or folder is hidden
      Throws:
      IOException - if there is an error reading the file/folder
    • getDataDir

      public static Path getDataDir(Bag bag)
      With bagit version 2.0 (.bagit) payload files are no longer in the "data" directory. This method accounts for this and will return the directory that contains the payload files
      Parameters:
      bag - that contains the payload files you want
      Returns:
      the directory that contains the payload files
    • getDataDir

      public static Path getDataDir(Version version, Path output)
      With bagit version 2.0 (.bagit) payload files are no longer in the "data" directory. This method accounts for this and will return the directory that contains the payload files
      Parameters:
      version - the bag version
      output - where the bag is being or was written to
      Returns:
      the payload directory for the output directory
    • getBagitDir

      public static Path getBagitDir(Bag bag)
      With bagit version 2.0 (.bagit) bagit specific files are no longer at the bag root directory. This method accounts for this and will return the directory that contains the bag specific files.
      Parameters:
      bag - the bag
      Returns:
      the directory which contains the bag specific files, like manifests or bagit.txt
    • getBagitDir

      public static Path getBagitDir(Version version, Path bagRoot)
      With bagit version 2.0 (.bagit) bagit specific files are no longer at the bag root directory. This method accounts for this and will return the directory that contains the bag specific files.
      Parameters:
      version - the bag version
      bagRoot - the root directory of the bag
      Returns:
      the directory which contains the bag specific files, like manifests or bagit.txt
    • generatePayloadOxum

      public static String generatePayloadOxum(Path dataDir) throws IOException
      Calculate the total file and byte count of the files in the payload directory
      Parameters:
      dataDir - the directory to calculate the payload-oxum
      Returns:
      the string representation of the payload-oxum value
      Throws:
      IOException - if there is an error reading any of the files