Java examples for java.io:URL
get URL Safe
//package com.java2s; public class Main { public static void main(String[] argv) { String url = "java2s.com"; System.out.println(getURLSafe(url)); }//w w w . j a v a 2 s .c o m private static final char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; public static String getURLSafe(String url) { if (url == null || "".equals(url)) return ""; StringBuffer strBuff = new StringBuffer(); char[] charArray = url.toCharArray(); for (int i = 0; i < charArray.length; i++) { if (charArray[i] == '<' || charArray[i] == '>') continue; strBuff.append(charArray[i]); } return strBuff.toString(); } public static String toString(byte[] data) { if (data == null) { return "null!"; } int l = data.length; char[] out = new char[l << 1]; // two characters form the hex value. for (int i = 0, j = 0; i < l; i++) { out[j++] = DIGITS[(0xF0 & data[i]) >>> 4]; out[j++] = DIGITS[0x0F & data[i]]; } return new String(out); } public static String toString(Object[] objs) { return toString(objs, false, ", "); } public static String toString(Object[] objs, boolean showOrder) { return toString(objs, showOrder, ","); } public static String toString(Object[] objs, boolean showOrder, String token) { if (objs == null) { return "null"; } int len = objs.length; StringBuffer sb = new StringBuffer(10 * len); for (int i = 0; i < len; i++) { if (showOrder) { sb.append(i).append(':'); } sb.append(objs[i]); if (i < len - 1) { sb.append(token); } } return sb.toString(); } }