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

com.arextest.schedule.utils.DecodeUtils Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package com.arextest.schedule.utils;

import java.util.Base64;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;

/**
 * @author wildeslam.
 * @create 2023/11/30 20:43
 */
public class DecodeUtils {

  private static final String PATTERN_STRING = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$";
  private static final Pattern BASE_64_PATTERN = Pattern.compile(PATTERN_STRING);

  public static Object decode(String requestMessage) {
    if (StringUtils.isEmpty(requestMessage)) {
      return requestMessage;
    }
    if (BASE_64_PATTERN.matcher(requestMessage).matches()) {
      return Base64.getDecoder().decode(requestMessage);
    }
    return requestMessage;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy