public static String stripSpaces(String str) {
        StringBuilder ret = new StringBuilder();
        boolean inQuotes = false;
        boolean inSpaceSequence = false;
        for (char c : str.toCharArray()) {
            if (Character.isWhitespace(c)) {
                if (inQuotes) {
                    ret.append(c);
                    continue;
                }
                if (!inSpaceSequence) {
                    // start of space sequence
                    inSpaceSequence = true;
                    ret.append(" ");
                }
            } else {
                if (inSpaceSequence) {
                    inSpaceSequence = false;
                }
                if (c == '\"') {
                    inQuotes = !inQuotes;
                }
                ret.append(c);
            }
        }
        return ret.toString();
    }
@Test
    public void testStripSpaces() {
        assertEquals("a b", ConfigUtils.stripSpaces("a   b"));
        assertEquals("\"a   b\"", ConfigUtils.stripSpaces("\"a   b\""));
        assertEquals("a b \"a   b\"", ConfigUtils.stripSpaces("a   b   \"a   b\""));
        assertEquals("a b", ConfigUtils.stripSpaces("a b"));
    }