55import java .io .UnsupportedEncodingException ;
66import java .net .URLDecoder ;
77import java .net .URLEncoder ;
8- import java .nio .charset .StandardCharsets ;
9- import java .util .HashMap ;
10- import java .util .Map ;
118
129public class URLUtils {
13- public String urlEncode (String content ){
10+ public String urlEncode (String content ) {
1411 try {
1512 return URLEncoder .encode (content , "UTF-8" );
1613 } catch (UnsupportedEncodingException e ) {
@@ -19,7 +16,7 @@ public String urlEncode(String content){
1916 return null ;
2017 }
2118
22- public String urlDecode (String content ){
19+ public String urlDecode (String content ) {
2320 try {
2421 return URLDecoder .decode (content , "UTF-8" );
2522 } catch (UnsupportedEncodingException e ) {
@@ -34,12 +31,12 @@ public static class URLBuilder {
3431 private String path = "" ;
3532 private QueryString queryParameters = new QueryString ();
3633
37- public URLBuilder (){
34+ public URLBuilder () {
3835
3936 }
4037
41- public String build (){
42- String url = protocol + "://" + domain ;
38+ public String build () {
39+ String url = protocol + "://" + domain ;
4340
4441 url += getFullPath ();
4542
@@ -71,10 +68,10 @@ public String getPath() {
7168 public String getFullPath () {
7269 String fullPath = "" ;
7370 if (!path .equals ("" ))
74- fullPath += (path .startsWith ("/" ) ? "" : "/" ) + path ;
71+ fullPath += (path .startsWith ("/" ) ? "" : "/" ) + path ;
7572
7673 if (queryParameters .size () > 0 )
77- fullPath += (fullPath .contains ("/" ) ? "" : "/" ) + "?" + queryParameters .toString ();
74+ fullPath += (fullPath .contains ("/" ) ? "" : "/" ) + "?" + queryParameters .toString ();
7875
7976 return fullPath ;
8077 }
@@ -97,7 +94,7 @@ public URLBuilder setQueryParameters(QueryString queryParameters) {
9794 return this ;
9895 }
9996
100- public URLBuilder setQueryParameter (String key , String value ){
97+ public URLBuilder setQueryParameter (String key , String value ) {
10198 queryParameters .set (key , value );
10299 return this ;
103100 }
@@ -106,7 +103,7 @@ public String toString() {
106103 return build ();
107104 }
108105
109- public static URLBuilder from (String url ){
106+ public static URLBuilder from (String url ) {
110107 URLBuilder urlBuilder = new URLBuilder ();
111108 String [] protocolAndUrl = url .split ("://" , 2 );
112109 urlBuilder .protocol = protocolAndUrl [0 ];
@@ -128,4 +125,5 @@ public static URLBuilder from(String url){
128125 return urlBuilder ;
129126 }
130127 }
128+
131129}
0 commit comments