io.github.nichetoolkit.rest.util.PathUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-toolkit-utils Show documentation
Show all versions of rest-toolkit-utils Show documentation
Rest toolkit utils project for Spring Boot
The newest version!
package io.github.nichetoolkit.rest.util;
import io.github.nichetoolkit.rest.constant.UtilConstants;
import org.springframework.util.ResourceUtils;
import java.io.File;
import java.io.FileNotFoundException;
/**
* PathUtils
* The path utils class.
* @author Cyan ([email protected])
* @since Jdk1.8
*/
public class PathUtils {
/**
* getRootPath
* The get root path getter method.
* @return {@link java.lang.String} The get root path return object is String
type.
* @see java.lang.String
*/
public static String getRootPath() {
File file;
try {
file = new File(ResourceUtils.getURL(UtilConstants.ROOT_PREFIX).getPath());
if(!file.exists()) {
file = new File(UtilConstants.EMPTY_PREFIX);
}
} catch (FileNotFoundException ignoredException) {
file = new File(UtilConstants.EMPTY_PREFIX);
}
return file.getAbsolutePath();
}
/**
* getChildPath
* The get child path getter method.
* @param childName {@link java.lang.String} The child name parameter is String
type.
* @return {@link java.lang.String} The get child path return object is String
type.
* @see java.lang.String
* @see java.lang.SuppressWarnings
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
public static String getChildPath(final String childName) {
String rootPath = getRootPath();
String staticPath = UtilConstants.STATIC_PREFIX.concat(File.separator).concat(childName).concat(File.separator);
File file = new File(rootPath, staticPath);
if(!file.exists()) {
file.mkdirs();
}
return file.getAbsolutePath();
}
}