br.com.jhonsapp.repository.util.PathUtil Maven / Gradle / Ivy
package br.com.jhonsapp.repository.util;
import java.io.File;
/**
* This class format the file path.
*
* @author Jhonathan Camacho
*
*/
public class PathUtil {
/**
* Format the path in this pattern. Ex: folder1/folder2/folder3/
*
* @param path
* the directory to be formatted.
*
* @return the formatted folder.
*/
public static final String pathFormat(String path) {
path = path.replaceAll("[/]", File.separator);
if (path.charAt(0) == '/')
path = path.substring(1);
if (path.charAt(path.length() - 1) != '/')
path = path + File.separator;
return path;
}
/**
* Gets the id of a string that contains the folder concatenated with the identifier.
*
* @param fullPath
* string containing the folder concatenated with the identifier.
*
* @return the identifier.
*/
public static final String getId(String fullPath) {
String values[] = fullPath.split("[/]");
return values[values.length - 1];
}
/**
* Gets the folder of a string that contains the folder concatenated with the identifier.
*
* @param fullPath
* string containing the folder concatenated with the identifier.
*
* @return the folders.
*/
public static final String getFolder(String fullPath) {
String values[] = fullPath.substring(1).split("[/]");
String folder = "";
for (int i = 0; i < values.length - 1; i++) {
folder = folder + values[i] + File.pathSeparator;
}
return pathFormat(folder);
}
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy