static private String encodeUri(final String uri){
  final StringTokenizer st=new StringTokenizer(uri,"/ ",true);
  final StringBuilder newUri=new StringBuilder("");
  while (st.hasMoreTokens()) {
    final String tok=st.nextToken();
    if (tok.equals("/"))     newUri.append("/");
 else     if (tok.equals(" "))     newUri.append("%20");
 else {
      try {
        newUri.append(URLEncoder.encode(tok,UTF8));
      }
 catch (      UnsupportedEncodingException uee) {
        throw new RuntimeException(uee);
      }
    }
  }
  return newUri.toString();
}

static private String encodeUri ( final String uri ) { final StringTokenizer st = new StringTokenizer ( uri , "/ " , true ) ; final StringBuilder newUri = new StringBuilder ( "" ) ; while ( st . hasMoreTokens ( ) ) { final String tok = st . nextToken ( ) ; if ( tok . equals ( "/" ) ) newUri . append ( "/" ) ; else if ( tok . equals ( " " ) ) newUri . append ( "%20" ) ; else { try { newUri . append ( URLEncoder . encode ( tok , UTF8 ) ) ; } catch ( UnsupportedEncodingException uee ) { throw new RuntimeException ( uee ) ; } } } return newUri . toString ( ) ; }
url - encodes everything between " / " - characters . encodes spaces as ' % 20 ' instead of ' + ' .
