Created
November 14, 2012 19:48
-
-
Save bohnman/4074310 to your computer and use it in GitHub Desktop.
Wraps Spring's UriUtils with the assumption that we're using UTF-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.web.util.UriUtils; | |
import java.io.UnsupportedEncodingException; | |
public class UriUtil { | |
private static final String ENCODING = "UTF-8"; | |
private UriUtil() { | |
} | |
public static String encodeScheme(String scheme) { | |
try { | |
return UriUtils.encodeScheme(scheme, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static String encodeAuthority(String authority) { | |
try { | |
return UriUtils.encodeAuthority(authority, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static String encodeUserInfo(String userInfo) { | |
try { | |
return UriUtils.encodeUserInfo(userInfo, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static String encodeHost(String host) { | |
try { | |
return UriUtils.encodeHost(host, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static String encodePort(String port) { | |
try { | |
return UriUtils.encodePort(port, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static String encodePath(String path) { | |
try { | |
return UriUtils.encodePath(path, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static String encodePathSegment(String segment) { | |
try { | |
return UriUtils.encodePathSegment(segment, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static String encodeQuery(String query) { | |
try { | |
return UriUtils.encodeQuery(query, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static String encodeQueryParam(String queryParam) { | |
try { | |
return UriUtils.encodeQueryParam(queryParam, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static String encodeFragment(String fragment) { | |
try { | |
return UriUtils.encodeFragment(fragment, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static String decode(String source) { | |
try { | |
return UriUtils.decode(source, ENCODING); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment