| | |
| | | retStr.append("%20");
|
| | | } else if (inStr.charAt(i) == '&') {
|
| | | retStr.append("%26");
|
| | | } else if (inStr.charAt(i) == '+') {
|
| | | retStr.append("%2B");
|
| | | } else {
|
| | | retStr.append(inStr.charAt(i));
|
| | | }
|
| | | i++;
|
| | | }
|
| | | return retStr.toString();
|
| | | }
|
| | |
|
| | | /**
|
| | | * Flatten the list of strings into a single string with the specified
|
| | | * separator.
|
| | | *
|
| | | * @param values
|
| | | * @param separator
|
| | | * @return flattened list
|
| | | */
|
| | | public static String flattenStrings(String[] values, String separator) {
|
| | | return flattenStrings(Arrays.asList(values), separator);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param bytes
|
| | | * @return byte array as hex string
|
| | | */
|
| | | private static String toHex(byte[] bytes) {
|
| | | public static String toHex(byte[] bytes) {
|
| | | StringBuilder sb = new StringBuilder(bytes.length * 2);
|
| | | for (int i = 0; i < bytes.length; i++) {
|
| | | if ((bytes[i] & 0xff) < 0x10) {
|
| | |
| | | * @return the first invalid character found or null if string is acceptable
|
| | | */
|
| | | public static Character findInvalidCharacter(String name) {
|
| | | char[] validChars = { '/', '.', '_', '-', '~' };
|
| | | char[] validChars = { '/', '.', '_', '-', '~', '+' };
|
| | | for (char c : name.toCharArray()) {
|
| | | if (!Character.isLetterOrDigit(c)) {
|
| | | boolean ok = false;
|
| | |
| | | // ignore unsupported charsets
|
| | | }
|
| | | }
|
| | | if (value.startsWith("\uFEFF")) {
|
| | | if (value != null && value.startsWith("\uFEFF")) {
|
| | | // strip UTF-8 BOM
|
| | | return value.substring(1);
|
| | | }
|