com.github.jscancella.internal.PathUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bagging Show documentation
Show all versions of bagging Show documentation
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.
package com.github.jscancella.internal;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.DosFileAttributes;
/**
* Responsible for providing some very basic functionality across multiple packages.
*/
public interface PathUtils {
/**
* Needed to get rid of findbugs "dodgy code warnings" in regards to getting the filename of a path as a string
*
* @param path the path that you which to get the filename as a string
*
* @return the filename or an empty string
*/
static String getFilename(final Path path){
String filename = "";
if(path != null){
final Path filenamePath = path.getFileName();
if(filenamePath != null){
filename = filenamePath.toString();
}
}
return filename;
}
/**
* 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
*
* @param path the file or folder to check if hidden
*
* @return if the file or folder is hidden
*
* @throws IOException if there is an error reading the file/folder
*/
static boolean isHidden(final Path path) throws IOException{
//cause Files.isHidden() doesn't work properly for windows if the file is a directory
boolean isHidden = Files.isHidden(path);
if (System.getProperty("os.name").contains("Windows")){
isHidden = Files.readAttributes(path, DosFileAttributes.class).isHidden() || Files.isHidden(path);
}
return isHidden;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy