org.somda.sdc.glue.common.helper.UrlUtf8 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of glue Show documentation
Show all versions of glue Show documentation
SDCri is a set of Java libraries that implements a network communication framework conforming
with the IEEE 11073 SDC specifications. This project implements the 11073-20702 SDC glue binding.
package org.somda.sdc.glue.common.helper;
import javax.annotation.Nullable;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
/**
* Helper to encode and decode URLs to and from UTF-8.
*/
public class UrlUtf8 {
/**
* Accepts a text and URL-encodes it based on UTF-8.
*
* @param text the text to encode.
* @return the encoded text or an empty string if text was null.
*/
public static String encode(@Nullable String text) {
return text == null ? "" : URLEncoder.encode(text, StandardCharsets.UTF_8);
}
/**
* Accepts a text and URL-decodes it based on UTF-8.
*
* @param text the text to decode.
* @return the decoded text or an empty string if text was null.
*/
public static String decode(@Nullable String text) {
return text == null ? "" : URLDecoder.decode(text, StandardCharsets.UTF_8);
}
}