public static String escape(String string){
  if (string == null || string.equals("")) {
    return string;
  }
  String prefix="";
  if (string.indexOf("://") != -1) {
    prefix=string.substring(0,string.indexOf("://") + 3);
    string=string.replaceFirst(prefix,"");
  }
  string=string.replaceAll("\\\\","/");
  if (string.startsWith("//")) {
    string="/" + string.replaceAll("/+","/");
  }
 else {
    string=string.replaceAll("/+","/");
  }
  return prefix.concat(string);
}

public static String escape ( String string ) { if ( string == null || string . equals ( "" ) ) { return string ; } String prefix = "" ; if ( string . indexOf ( "://" ) != - 1 ) { prefix = string . substring ( 0 , string . indexOf ( "://" ) + 3 ) ; string = string . replaceFirst ( prefix , "" ) ; } string = string . replaceAll ( "\\\\" , "/" ) ; if ( string . startsWith ( "//" ) ) { string = "/" + string . replaceAll ( "/+" , "/" ) ; } else { string = string . replaceAll ( "/+" , "/" ) ; } return prefix . concat ( string ) ; }
escapes double slashes ( / / ) and replace all backslashes ( \ ) with slashes ( / ) . additionally preserves unc paths .
