encodes a String to Base64 String

@param plain String to encode
@return encoded String
@throws CoderException
@throws UnsupportedEncodingException
1305
public static String encodeFromString(String plain, String charset) throws CoderException, UnsupportedEncodingException {
	return encode(plain.getBytes(charset));
    }
1106190
public static String encode(String value) throws UnsupportedEncodingException {
        if (isNullOrEmpty(value)) return value;
        return URLEncoder.encode(value, URL_ENCODING);
    }
654661
public String decodeToString(final byte[] input, final String outputCharset)
        throws UnsupportedEncodingException {

        return new String(decode(input), outputCharset);
    }
1034886
public static Encoding getEncodingFromString(String encodingString){
        if(encodingString == null || encodingString.isEmpty() || encodingString.equalsIgnoreCase("Plain")){
            return Encoding.Plain;
        } else if(encodingString.equalsIgnoreCase("gzip")){
            return Encoding.Gzip;
        } else {
            throw new IllegalArgumentException("Unsupported encoding");
        }
    }
941126
def _encode_string(string):
    """"""
    if not isinstance(string, bytes):
        string = string.encode('utf8')
    return ffi.new('char[]', string)
987043
def encode(string, encoding=None, errors=None):
    
    if encoding is None:
        encoding = getpreferredencoding()
    if errors is None:
        errors = getpreferrederrors()
    return string.encode(encoding, errors)
877155
public static String encodeToString(byte[] src) {
        return src == null ? null : Base64.getEncoder().encodeToString(src);
    }
186496
private static String base64EncodeToString(String s) {
    final byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
    return Base64.encodeBase64String(bytes);
  }
860219
@Pure
	@Inline(value = "Base64Coder.encode($1, ($1).length)", imported = {Base64Coder.class})
	public static char[] encode(byte[] in) {
		return encode(in, in.length);
	}
18063
static XMLObject fromDeflatedBase64(String base64Encoded) {
        requireNonNull(base64Encoded, "base64Encoded");

        final byte[] base64decoded;
        try {
            base64decoded = Base64.getMimeDecoder().decode(base64Encoded);
        } catch (IllegalArgumentException e) {
            throw new SamlException("failed to decode a deflated base64 string", e);
        }

        final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        try (InflaterOutputStream inflaterOutputStream =
                     new InflaterOutputStream(bytesOut, new Inflater(true))) {
            inflaterOutputStream.write(base64decoded);
        } catch (IOException e) {
            throw new SamlException("failed to inflate a SAML message", e);
        }

        return SamlMessageUtil.deserialize(bytesOut.toByteArray());
    }
909841
protected byte[] encodeString(String in) {
    byte[] rv = null;
    try {
      rv = in.getBytes(this.charset);
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
    return rv;
  }
947929
private byte[] encode(byte[] input) throws EncoderException
    {
        if (encoder != null)
        {
            return encoder.encode(input);
        }
        else
        {
            return DEFAULT_CODER.encode(input);
        }
    }
1182964
public static String encode( String string ) {
        byte[] bytes;
        try {
            bytes = string.getBytes(PREFERRED_ENCODING);
        } catch( UnsupportedEncodingException uee ) {
            bytes = string.getBytes();
        }
        return encodeBytes(bytes);
    }
662099
public static String encodeBase64(String content, Charset charset, TestContext context) {
        return new EncodeBase64Function().execute(Arrays.asList(content, charset.displayName()), context);
    }
1267709
public static String encodeString(String string,String charset)
    {
        if (charset==null)
            charset=StringUtil.__ISO_8859_1;
        byte[] bytes=null;
        try
        {
            bytes=string.getBytes(charset);
        }
        catch(UnsupportedEncodingException e)
        {
            log.warn(LogSupport.EXCEPTION,e);
            bytes=string.getBytes();
        }
        
        int len=bytes.length;
        byte[] encoded= new byte[bytes.length*3];
        int n=0;
        boolean noEncode=true;
        
        for (int i=0;i<len;i++)
        {
            byte b = bytes[i];
            
            if (b==' ')
            {
                noEncode=false;
                encoded[n++]=(byte)'+';
            }
            else if (b>='a' && b<='z' ||
                     b>='A' && b<='Z' ||
                     b>='0' && b<='9')
            {
                encoded[n++]=b;
            }
            else
            {
                noEncode=false;
                encoded[n++]=(byte)'%';
                byte nibble= (byte) ((b&0xf0)>>4);
                if (nibble>=10)
                    encoded[n++]=(byte)('A'+nibble-10);
                else
                    encoded[n++]=(byte)('0'+nibble);
                nibble= (byte) (b&0xf);
                if (nibble>=10)
                    encoded[n++]=(byte)('A'+nibble-10);
                else
                    encoded[n++]=(byte)('0'+nibble);
            }
        }

        if (noEncode)
            return string;
        
        try
        {    
            return new String(encoded,0,n,charset);
        }
        catch(UnsupportedEncodingException e)
        {
            log.warn(LogSupport.EXCEPTION,e);
            return new String(encoded,0,n);
        }
    }
966576
private static byte[] base64Decode(String value) {
    if (value == null) {
      return null;
    }
    
    try {
      return Base64.decodeBase64(value.getBytes("UTF-8"));
    }
    catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
  }
933314
public static String base64dec(String str) {
		if (str == null) {
			return "";
		}
		try {
			return new String(Base64.decodeBase64(str), Config.DEFAULT_ENCODING);
		} catch (UnsupportedEncodingException ex) {
			return "";
		}
	}