@Test public void URIEncodePath() { assertEquals("", Util.URIEncodePath("")); assertEquals("/", Util.URIEncodePath("/")); assertEquals("a", Util.URIEncodePath("a")); assertEquals("%09", Util.URIEncodePath("\t")); assertEquals("a%2Bb", Util.URIEncodePath("a+b")); assertEquals("a%20b", Util.URIEncodePath("a b")); assertEquals("/a Util.URIEncodePath("/a assertEquals("foo%3A%3Abar%3A%3Atest.js", Util.URIEncodePath("foo::bar::test.js")); assertEquals("bl%C3%A5b%C3%A6rsyltet%C3%B8y", Util.URIEncodePath("bl\u00E5b\u00E6rsyltet\u00F8y")); }
public static String URIEncodePath(String path) { StringBuilder sb = new StringBuilder(path.length()); for (byte b : path.getBytes(StandardCharsets.UTF_8)) { if ((b == '/') || (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') || (b == '.') || (b == '-') || (b == '_') || (b == '*')) { sb.append((char) b); } else { sb.append('%'); int u = b & 0xFF; if (u <= 0x0F) { sb.append('0'); } sb.append(Integer.toHexString(u).toUpperCase(Locale.ROOT)); } } return sb.toString(); }
Util { public static String URIEncodePath(String path) { StringBuilder sb = new StringBuilder(path.length()); for (byte b : path.getBytes(StandardCharsets.UTF_8)) { if ((b == '/') || (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') || (b == '.') || (b == '-') || (b == '_') || (b == '*')) { sb.append((char) b); } else { sb.append('%'); int u = b & 0xFF; if (u <= 0x0F) { sb.append('0'); } sb.append(Integer.toHexString(u).toUpperCase(Locale.ROOT)); } } return sb.toString(); } }
Util { public static String URIEncodePath(String path) { StringBuilder sb = new StringBuilder(path.length()); for (byte b : path.getBytes(StandardCharsets.UTF_8)) { if ((b == '/') || (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') || (b == '.') || (b == '-') || (b == '_') || (b == '*')) { sb.append((char) b); } else { sb.append('%'); int u = b & 0xFF; if (u <= 0x0F) { sb.append('0'); } sb.append(Integer.toHexString(u).toUpperCase(Locale.ROOT)); } } return sb.toString(); } private  Util(); }
Util { public static String URIEncodePath(String path) { StringBuilder sb = new StringBuilder(path.length()); for (byte b : path.getBytes(StandardCharsets.UTF_8)) { if ((b == '/') || (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') || (b == '.') || (b == '-') || (b == '_') || (b == '*')) { sb.append((char) b); } else { sb.append('%'); int u = b & 0xFF; if (u <= 0x0F) { sb.append('0'); } sb.append(Integer.toHexString(u).toUpperCase(Locale.ROOT)); } } return sb.toString(); } private  Util(); static String prehtmlize(String s); static String prehtmlize(CharSequence q); static void qurlencode(String str, Appendable dest); static String htmlize(String s); static String htmlize(CharSequence q); static void htmlize(CharSequence q, Appendable dest, boolean pre); static void htmlize(CharSequence q, Appendable dest); static void htmlize(char[] cs, int length, Appendable dest); static String breadcrumbPath(String urlPrefix, String path); static String breadcrumbPath(String urlPrefix, String path, char sep); static String breadcrumbPath(String urlPrefix, String path,
            char sep, String urlPostfix, boolean compact); static String breadcrumbPath(String urlPrefix, String path,
            char sep, String urlPostfix, boolean compact, boolean isDir); static String getCanonicalPath(String path, char sep); static String getEmail(String author); static String readableSize(long num); static String readableCount(long count); static String encode(String s); static void encode(String s, Appendable dest); static String encodeURL(String urlStr); static void readableLine(int num, Writer out, Annotation annotation,
            String userPageLink, String userPageSuffix, String project); static void readableLine(int num, Writer out, Annotation annotation, String userPageLink,
            String userPageSuffix, String project, boolean skipNewline); static String path2uid(String path, String date); static String uid2url(String uid); static String fixPathIfWindows(String path); static void writeHAD(Writer out, String ctxE, String entry,
            boolean is_dir); static String URIEncode(String q); static void URIEncode(String str, Appendable dest); static void appendQuery(StringBuilder buf, String key,
            String value); static String URIEncodePath(String path); static String formQuoteEscape(String q); static String[] diffline(StringBuilder line1, StringBuilder line2); @SuppressWarnings("boxing") static void dumpConfiguration(Appendable out); static void dump(Writer out, Reader in); static boolean dump(Writer out, File dir, String filename,
            boolean compressed); static boolean dump(Writer out, File file, boolean compressed); static boolean dumpXref(Writer out, File file, boolean compressed,
            String contextPath); static void dumpXref(Writer out, Reader in, String contextPath); static String jsStringLiteral(String str); static String stripPathPrefix(String prefix, String fullPath); static String createSlider(int offset, int limit, int size); static String createSlider(int offset, int limit, long size, HttpServletRequest request); static boolean isHttpUri(String string); static String redactUrl(String path); static String linkify(String url); static String linkify(String url, boolean newTab); static String buildLink(String name, Map<String, String> attrs); static String buildLink(String name, String url); static String buildLink(String name, String url, boolean newTab); static String linkifyPattern(String text, Pattern pattern, String name, String url); static String completeUrl(String url, HttpServletRequest req); static Map<String, List<String>> getQueryParams(final URL url); }
Util { public static String URIEncodePath(String path) { StringBuilder sb = new StringBuilder(path.length()); for (byte b : path.getBytes(StandardCharsets.UTF_8)) { if ((b == '/') || (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') || (b == '.') || (b == '-') || (b == '_') || (b == '*')) { sb.append((char) b); } else { sb.append('%'); int u = b & 0xFF; if (u <= 0x0F) { sb.append('0'); } sb.append(Integer.toHexString(u).toUpperCase(Locale.ROOT)); } } return sb.toString(); } private  Util(); static String prehtmlize(String s); static String prehtmlize(CharSequence q); static void qurlencode(String str, Appendable dest); static String htmlize(String s); static String htmlize(CharSequence q); static void htmlize(CharSequence q, Appendable dest, boolean pre); static void htmlize(CharSequence q, Appendable dest); static void htmlize(char[] cs, int length, Appendable dest); static String breadcrumbPath(String urlPrefix, String path); static String breadcrumbPath(String urlPrefix, String path, char sep); static String breadcrumbPath(String urlPrefix, String path,
            char sep, String urlPostfix, boolean compact); static String breadcrumbPath(String urlPrefix, String path,
            char sep, String urlPostfix, boolean compact, boolean isDir); static String getCanonicalPath(String path, char sep); static String getEmail(String author); static String readableSize(long num); static String readableCount(long count); static String encode(String s); static void encode(String s, Appendable dest); static String encodeURL(String urlStr); static void readableLine(int num, Writer out, Annotation annotation,
            String userPageLink, String userPageSuffix, String project); static void readableLine(int num, Writer out, Annotation annotation, String userPageLink,
            String userPageSuffix, String project, boolean skipNewline); static String path2uid(String path, String date); static String uid2url(String uid); static String fixPathIfWindows(String path); static void writeHAD(Writer out, String ctxE, String entry,
            boolean is_dir); static String URIEncode(String q); static void URIEncode(String str, Appendable dest); static void appendQuery(StringBuilder buf, String key,
            String value); static String URIEncodePath(String path); static String formQuoteEscape(String q); static String[] diffline(StringBuilder line1, StringBuilder line2); @SuppressWarnings("boxing") static void dumpConfiguration(Appendable out); static void dump(Writer out, Reader in); static boolean dump(Writer out, File dir, String filename,
            boolean compressed); static boolean dump(Writer out, File file, boolean compressed); static boolean dumpXref(Writer out, File file, boolean compressed,
            String contextPath); static void dumpXref(Writer out, Reader in, String contextPath); static String jsStringLiteral(String str); static String stripPathPrefix(String prefix, String fullPath); static String createSlider(int offset, int limit, int size); static String createSlider(int offset, int limit, long size, HttpServletRequest request); static boolean isHttpUri(String string); static String redactUrl(String path); static String linkify(String url); static String linkify(String url, boolean newTab); static String buildLink(String name, Map<String, String> attrs); static String buildLink(String name, String url); static String buildLink(String name, String url, boolean newTab); static String linkifyPattern(String text, Pattern pattern, String name, String url); static String completeUrl(String url, HttpServletRequest req); static Map<String, List<String>> getQueryParams(final URL url);  }