All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.somda.sdc.glue.common.helper.UrlUtf8 Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 5.1.1
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy