public static URI replaceQuery(URI uri,String query) throws URISyntaxException {
  String schemeSpecificPart=uri.getRawSchemeSpecificPart();
  int questionMark=schemeSpecificPart.lastIndexOf("?");
  if (questionMark < schemeSpecificPart.lastIndexOf(")")) {
    questionMark=-1;
  }
  if (questionMark > 0) {
    schemeSpecificPart=schemeSpecificPart.substring(0,questionMark);
  }
  if (query != null && query.length() > 0) {
    schemeSpecificPart+="?" + query;
  }
  return new URI(uri.getScheme(),schemeSpecificPart,uri.getFragment());
}

public static URI replaceQuery ( URI uri , String query ) throws URISyntaxException { String schemeSpecificPart = uri . getRawSchemeSpecificPart ( ) ; int questionMark = schemeSpecificPart . lastIndexOf ( "?" ) ; if ( questionMark < schemeSpecificPart . lastIndexOf ( ")" ) ) { questionMark = - 1 ; } if ( questionMark > 0 ) { schemeSpecificPart = schemeSpecificPart . substring ( 0 , questionMark ) ; } if ( query != null && query . length ( ) > 0 ) { schemeSpecificPart += "?" + query ; } return new URI ( uri . getScheme ( ) , schemeSpecificPart , uri . getFragment ( ) ) ; }
creates a uri with the given query , removing an previous query value from the given uri .
