@@ -1114,6 +1114,107 @@ public static String ensureTrailingPathSlash(String path, char slash)
11141114 return path ;
11151115 }
11161116
1117+ /**
1118+ * Constructs new path based on provided pre and post path sections
1119+ * Ensures resulting path is properly delimited at the point of concatenation
1120+ * Uses Linux path style path separator
1121+ *
1122+ * @param prefixPath - the prefix path
1123+ * @param postfixPath - the postfix path
1124+ * @return - new path comprised of path prefix a linux style path separator and path postfix
1125+ */
1126+ public static String appendLinuxPathSections (String prefixPath , String postfixPath )
1127+ {
1128+ return appendPathSections (prefixPath , LINUX_SEP , postfixPath );
1129+ }
1130+
1131+ /**
1132+ * Constructs new path based on provided pre and post path sections
1133+ * Ensures resulting path is properly delimited at the point of concatenation
1134+ * Uses Windows path style path separator
1135+ *
1136+ * @param prefixPath - the prefix path
1137+ * @param postfixPath - the postfix path
1138+ * @return - new path comprised of path prefix a windows style path separator and path postfix
1139+ */
1140+ public static String appendWindowsPathSections (String prefixPath , String postfixPath )
1141+ {
1142+ return appendPathSections (prefixPath , WIN_SEP , postfixPath );
1143+ }
1144+
1145+ /**
1146+ * Constructs new path based on provided pre and post path sections
1147+ * Ensures resulting path is properly delimited at the point of concatenation
1148+ * Infers proper path separator on presence of Linux or Windows style path separator in prefix path
1149+ *
1150+ * @param prefixPath - the prefix path
1151+ * @param postfixPath - the postfix path
1152+ * @return - new path comprised of path prefix a path separator and path postfix
1153+ * @throws Exception - Invalid paths, indiscernible path style
1154+ */
1155+ public static String appendPathSections (String prefixPath , String postfixPath ) throws Exception
1156+ {
1157+ if (prefixPath == null )
1158+ prefixPath = "" ;
1159+
1160+ if (postfixPath == null )
1161+ postfixPath = "" ;
1162+
1163+ if (prefixPath .length () == 0 && postfixPath .length () == 0 )
1164+ return "" ;
1165+
1166+ try
1167+ {
1168+ char pathSep = inferPathSeperatorType (prefixPath .length () != 0 ? prefixPath : postfixPath );
1169+ return appendPathSections (prefixPath , pathSep , postfixPath );
1170+ }
1171+ catch (Exception e )
1172+ {
1173+ throw new Exception ("Could not append path sections, ensure original path sections are valid and contain path seperator" );
1174+ }
1175+ }
1176+
1177+ /**
1178+ * Constructs new path based on provided pre and post path sections
1179+ * Ensures resulting path is properly delimited at the point of concatenation
1180+ * Uses provided char as delimiter between pre and post path sections
1181+ *
1182+ * @param prefixPath - the prefix path
1183+ * @param slash - separator to use when appending path sections
1184+ * @param postfixPath - the postfix path
1185+ * @return - new path comprised of path prefix a path separator and path postfix
1186+ */
1187+ public static String appendPathSections (String prefixPath , char slash , String postfixPath )
1188+ {
1189+ prefixPath = trimTrailing (prefixPath );
1190+
1191+ if (prefixPath .length () == 0 || prefixPath .charAt (prefixPath .length ()-1 ) != slash )
1192+ prefixPath = prefixPath + slash ;
1193+
1194+ postfixPath = postfixPath .trim ();
1195+
1196+ if (postfixPath .length () > 0 && postfixPath .charAt (0 ) == slash )
1197+ prefixPath = prefixPath + postfixPath .substring (1 );
1198+ else
1199+ prefixPath = prefixPath + postfixPath ;
1200+
1201+ return prefixPath ;
1202+ }
1203+
1204+ /**
1205+ * Infers path style (linux/windows) based on presence of Linux separator
1206+ * @param path - the path
1207+ * @return - new path comprised of path prefix a path separator and path postfix
1208+ * @throws Exception - Invalid paths, indiscernible path style
1209+ */
1210+ public static char inferPathSeperatorType (String path ) throws Exception
1211+ {
1212+ if (path .length () == 0 )
1213+ throw new Exception ("Zero len path detected!" );
1214+
1215+ return path .contains (Character .toString (LINUX_SEP )) ? LINUX_SEP : WIN_SEP ;
1216+ }
1217+
11171218 /**
11181219 * Removes trailing whitespace characters from a string.
11191220 *
0 commit comments