QuotedStringTokenizer extends StringTokenizer { public static String quote(String s) { if (s == null) return null; if (s.length() == 0) return "\"\""; StringBuilder b = new StringBuilder(s.length() + 8); quote(b, s); return b.toString(); } QuotedStringTokenizer(String str, String delimiter, boolean returnDelimiters, boolean returnQuotes);  QuotedStringTokenizer(String str, String delimiter, boolean returnDelimiters);  QuotedStringTokenizer(String str, String delimiter);  QuotedStringTokenizer(String str); static String quoteIfNeeded(String s, String delim); static String quote(String s); static void quoteOnly(Appendable buffer, String input); static void quote(Appendable buffer, String input); static String unquoteOnly(String s); static String unquoteOnly(String s, boolean lenient); static String unquote(String s); static String unquote(String s, boolean lenient); static boolean isQuoted(String s); @Override boolean hasMoreTokens(); @Override String nextToken(); @Override String nextToken(String delim); @Override boolean hasMoreElements(); @Override Object nextElement(); @Override int countTokens(); boolean getDouble(); void setDouble(boolean d); boolean getSingle(); void setSingle(boolean single);  }
@Test void testQuote() { StringBuilder buf = new StringBuilder(); buf.setLength(0); QuotedStringTokenizer.quote(buf, "abc \n efg"); assertEquals("\"abc \\n efg\"", buf.toString()); buf.setLength(0); QuotedStringTokenizer.quote(buf, "abcefg"); assertEquals("\"abcefg\"", buf.toString()); buf.setLength(0); QuotedStringTokenizer.quote(buf, "abcefg\""); assertEquals("\"abcefg\\\"\"", buf.toString()); }