@@ -1114,6 +1114,121 @@ public static String ensureTrailingPathSlash(String path, char slash)
1114
1114
return path ;
1115
1115
}
1116
1116
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 contain path seperator" );
1174
+ }
1175
+ }
1176
+
1177
+ /**
1178
+ * Constructs new path based on provided pre and post path sections and string representation of useLinuxSep directive
1179
+ * Linux style separator is used if useLinuxSep resolves to the literal "true" otherwise Windows separator is used.
1180
+ *
1181
+ * @param prefixPath - the prefix path
1182
+ * @param postfixPath - the postfix path
1183
+ * @param useLinuxSep - directive to use linux path separator represented as a literal string
1184
+ * @return - new path comprised of path prefix a path separator and path postfix
1185
+ */
1186
+ public static String appendPathSections (String prefixPath , String postfixPath , String useLinuxSep )
1187
+ {
1188
+ return appendPathSections (prefixPath , useLinuxSep .equalsIgnoreCase ("true" ) ? LINUX_SEP : WIN_SEP , postfixPath );
1189
+ }
1190
+
1191
+ /**
1192
+ * Constructs new path based on provided pre and post path sections
1193
+ * Ensures resulting path is properly delimited at the point of concatenation
1194
+ * Uses provided char as delimiter between pre and post path sections
1195
+ *
1196
+ * @param prefixPath - the prefix path
1197
+ * @param slash - separator to use when appending path sections
1198
+ * @param postfixPath - the postfix path
1199
+ * @return - new path comprised of path prefix a path separator and path postfix
1200
+ */
1201
+ public static String appendPathSections (String prefixPath , char slash , String postfixPath )
1202
+ {
1203
+ prefixPath = trimTrailing (prefixPath );
1204
+
1205
+ if (prefixPath .length () == 0 || prefixPath .charAt (prefixPath .length ()-1 ) != slash )
1206
+ prefixPath = prefixPath + slash ;
1207
+
1208
+ postfixPath = postfixPath .trim ();
1209
+
1210
+ if (postfixPath .length () > 0 && postfixPath .charAt (0 ) == slash )
1211
+ prefixPath = prefixPath + postfixPath .substring (1 );
1212
+ else
1213
+ prefixPath = prefixPath + postfixPath ;
1214
+
1215
+ return prefixPath ;
1216
+ }
1217
+
1218
+ /**
1219
+ * Infers path style (linux/windows) based on presence of Linux separator
1220
+ * @param path
1221
+ * @return - new path comprised of path prefix a path separator and path postfix
1222
+ * @throws Exception - Invalid paths, indiscernible path style
1223
+ */
1224
+ public static char inferPathSeperatorType (String path ) throws Exception
1225
+ {
1226
+ if (path .length () == 0 )
1227
+ throw new Exception ("Zero len path detected!" );
1228
+
1229
+ return path .contains (Character .toString (LINUX_SEP )) ? LINUX_SEP : WIN_SEP ;
1230
+ }
1231
+
1117
1232
/**
1118
1233
* Removes trailing whitespace characters from a string.
1119
1234
*
0 commit comments