* UTF-8 encoding is used by default for % encoded characters. This may be * overridden with the org.mortbay.util.URI.charset system property. * * @see UrlEncoded * @author Greg Wilkins (gregw) */ public class Utils { /* ------------------------------------------------------------ */ /** * Encode a URI path. * * @param path * The path the encode * @param buf * StringBuffer to encode path into (or null) * @return The StringBuffer or null if no substitutions required. */ public static StringBuffer encodePath(StringBuffer buf, String path) { if (buf == null) { loop: for (int i = 0; i < path.length(); i++) { char c = path.charAt(i); switch (c) { case '%': case '?': case ';': case '#': case ' ': buf = new StringBuffer(path.length() << 1); break loop; } } if (buf == null) return null; } synchronized (buf) { for (int i = 0; i < path.length(); i++) { char c = path.charAt(i); switch (c) { case '%': buf.append("%25"); continue; case '?': buf.append("%3F"); continue; case ';': buf.append("%3B"); continue; case '#': buf.append("%23"); continue; case ' ': buf.append("%20"); continue; default: buf.append(c); continue; } } } return buf; } }