Skip to content

Instantly share code, notes, and snippets.

@wyukawa
Created July 7, 2015 07:54
Show Gist options
  • Select an option

  • Save wyukawa/d7576e00d82e7931f36f to your computer and use it in GitHub Desktop.

Select an option

Save wyukawa/d7576e00d82e7931f36f to your computer and use it in GitHub Desktop.
urlencode/urldecode
@Nullable
@Description("encode url")
@ScalarFunction
@SqlType(StandardTypes.VARCHAR)
public static Slice urlEncode(@SqlType(StandardTypes.VARCHAR) Slice url, @SqlType(StandardTypes.VARCHAR) Slice enc)
{
if ((url == null) || (enc == null)) {
return null;
}
try {
return slice(URLEncoder.encode(url.toString(UTF_8), enc.toString(UTF_8)));
}
catch (UnsupportedEncodingException e) {
return null;
}
}
@Nullable
@Description("decode url")
@ScalarFunction
@SqlType(StandardTypes.VARCHAR)
public static Slice urlDecode(@SqlType(StandardTypes.VARCHAR) Slice url, @SqlType(StandardTypes.VARCHAR) Slice enc)
{
if ((url == null) || (enc == null)) {
return null;
}
try {
return slice(URLDecoder.decode(url.toString(UTF_8), enc.toString(UTF_8)));
}
catch (UnsupportedEncodingException e) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment