/** * Concatenates the two urls with respect to leading and trailing slashes. * * @return the concatenated url of the two arguments */ public static String concat(String prefix, String suffix) { if (prefix == null) throw new IllegalArgumentException("Argument prefix is null"); if (suffix == null) throw new IllegalArgumentException("Argument suffix is null"); prefix = adjustSeparator(prefix); suffix = adjustSeparator(suffix); prefix = removeDoubleSeparator(prefix); suffix = removeDoubleSeparator(suffix); if (!prefix.endsWith(File.separator) && !suffix.startsWith(File.separator)) prefix += File.separator; if (prefix.endsWith(File.separator) && suffix.startsWith(File.separator)) suffix = suffix.substring(1); prefix += suffix; return prefix; }
/** * Concatenates the path elements with respect to leading and trailing slashes. * * @param parts * the parts to concat * @return the concatenated path */ public static String concat(String[] parts) { if (parts == null) throw new IllegalArgumentException("Argument parts is null"); if (parts.length == 0) throw new IllegalArgumentException("Array parts is empty"); String path = removeDoubleSeparator(adjustSeparator(parts[0])); for (int i = 1; i < parts.length; i++) { path = concat(path, removeDoubleSeparator(adjustSeparator(parts[i]))); } return path; }