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

com.undefinedlabs.scope.utils.UrlUtils Maven / Gradle / Ivy

package com.undefinedlabs.scope.utils;

import com.undefinedlabs.scope.logger.ScopeLogger;
import com.undefinedlabs.scope.logger.ScopeLoggerResolver;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class UrlUtils {

  private static final ScopeLogger LOGGER = ScopeLoggerResolver.INSTANCE.get();
  private static final String UTF_8 = "UTF-8";

  public static String encodeUtf8(final String str) {
    if (str == null) {
      return null;
    }

    try {
      return URLEncoder.encode(str, UTF_8);
    } catch (final UnsupportedEncodingException e) {
      LOGGER.error("Could not encode " + str + " into " + UTF_8);
      return str;
    }
  }

  public static String decodeUtf8(final String str) {
    if (str == null) {
      return null;
    }

    try {
      return URLDecoder.decode(str, "UTF-8");
    } catch (final UnsupportedEncodingException e) {
      LOGGER.error("Could not decode " + str + " into " + UTF_8);
      return str;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy