Newer
Older
url-utils / src / main / java / io / ljunggren / url / utils / UrlUtils.java
@Alex Ljunggren Alex Ljunggren on 4 Feb 2025 676 bytes Initial commit
package io.ljunggren.url.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class UrlUtils {
    
    public static String encode(String string) throws UnsupportedEncodingException {
        if (string == null) {
            return null;
        }
        return URLEncoder.encode(string, StandardCharsets.UTF_8.toString());
    }

    public static String decode(String string) throws UnsupportedEncodingException {
        if (string == null) {
            return null;
        }
        return URLDecoder.decode(string, StandardCharsets.UTF_8.toString());
    }

}