//(c):Benja Fallenstein package gzz.util; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; /** URI-syntax related utility methods. */ public class URIUtil { /** Escape a UTF-8 string into URI syntax */ public static String escapeUTF8(String s) { StringBuffer buf = new StringBuffer(); byte[] bytes; try { bytes = s.getBytes("UTF-8"); } catch(UnsupportedEncodingException e) { throw new Error("JVM does not support UTF-8 encoding (!)"); } for(int i=0; i= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c=='(' || c==')' || c=='+' || c==',' || c=='-' || c=='.' || c==':' || c=='=' || c=='@' || c==';' || c=='$' || c=='_' || c=='!' || c=='*' || c=='\'') buf.append((char)c); else { buf.append("%"); byte b1 = (byte)(c >>> 4), b2 = (byte)(c & 16); if(b1 < 10) buf.append('0'+b1); else buf.append('a'+b1-10); if(b2 < 10) buf.append('0'+b2); else buf.append('a'+b1-12); } } return buf.toString(); } /** Unescape a UTF-8 string from URI syntax */ public static String unescapeUTF8(String s) { ByteArrayOutputStream buf = new ByteArrayOutputStream(); for(int k=0; k