|
@@ -5,8 +5,6 @@ import java.io.IOException;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLDecoder;
|
|
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-
|
|
|
/**
|
|
|
* 路径工具
|
|
|
*
|
|
@@ -22,8 +20,69 @@ public class PathUtil {
|
|
|
* @return
|
|
|
*/
|
|
|
public static String getCanonicalPath(String path) {
|
|
|
- path = path.replaceAll("\\+", "/").replaceAll("/+", "/").replaceAll("/\\./", "/");
|
|
|
- return StringUtils.replace(path, "/", File.separator);
|
|
|
+ path = path.replaceAll("\\\\+", "/");
|
|
|
+ path = path.replaceAll("/+", "/");
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 以"/"开头
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param path
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String startsWithSeparator(String path) {
|
|
|
+ path = getCanonicalPath(path);
|
|
|
+ if (path.startsWith("/")) {
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+ return "/" + path;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 不以"/"开头
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param path
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String startsWithoutSeparator(String path) {
|
|
|
+ path = getCanonicalPath(path);
|
|
|
+ if (path.startsWith("/")) {
|
|
|
+ return path.substring(1);
|
|
|
+ }
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 以"/"结尾
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param path
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String endsWithSeparator(String path) {
|
|
|
+ path = getCanonicalPath(path);
|
|
|
+ if (path.endsWith("/")) {
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+ return path + "/";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 不以"/"结尾
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param path
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String endsWithoutSeparator(String path) {
|
|
|
+ path = getCanonicalPath(path);
|
|
|
+ if (path.endsWith("/")) {
|
|
|
+ return path.substring(0, path.length() - 1);
|
|
|
+ }
|
|
|
+ return path;
|
|
|
}
|
|
|
|
|
|
/**
|