对字符串做base64<br>
@param rawStr<br>
@param encoding<br>
@return<br>
@throws IOException
425532
public static String base64Encode(String rawStr,String encoding) throws IOException{
		byte [] rawByte = rawStr.getBytes(encoding);
		return new String(SecureUtil.base64Encode(rawByte),encoding);
	}
17252
public static final String base64Decode(String str) {
        if (str == null) {
            return null;
        } else {
            byte data[] = getBytes(str);
            return toString(base64Decode(data));
        }
    }
1066069
private static String getEncodingToUse(String encoding)
    {
        //get encoding
        String updatedEncoding=encoding;
        if(updatedEncoding==null)
        {
            updatedEncoding=IOHelper.getDefaultEncoding();
        }
        
        return updatedEncoding;
    }
574952
public static Charset getCharset(final InputStream inputStream) throws IOException
    {
        final Charset resultCharset;
        final byte[] buffer = new byte[192];
        final int reading = ByteStreams.read(inputStream, buffer, 0, 192);
        if (4 > reading)
        {
            resultCharset = Charset.forName(EncodingUtils.DEFAULT_ENCODING);
        }
        else
        {
            final long computed = (0xFF000000 & (buffer[0] << 24)) |
                    (0x00FF0000 & (buffer[1] << 16)) |
                    (0x0000FF00 & (buffer[2] << 8)) |
                    (0x000000FF & buffer[3]);
            if (0x0000FEFFL == computed || 0xFFFE0000L == computed)
            {
                resultCharset = Charset.forName("UCS-4");
            }
            else if (0x0000003CL == computed)
            {
                resultCharset = Charset.forName("UCS-4BE");
            }
            else if (0x3C000000L == computed)
            {
                resultCharset = Charset.forName("UCS-4LE");
            }
            else if (0x003C003FL == computed)
            {
                resultCharset = Charset.forName("UTF-16BE");
            }
            else if (0x3C003F00L == computed)
            {
                resultCharset = Charset.forName("UTF-16LE");
            }
            else if (0x3C3F786DL == computed || 0x4C6FA794L == computed)
            {
                resultCharset = EncodingUtils.getXmlCharsetEncoding(buffer);
            }
            else if (0xFEFF0000L == (computed & 0xFFFF0000L))
            {
                resultCharset = Charset.forName("UTF-16");
            }
            else if (0xFFFE0000L == (computed & 0xFFFF0000L))
            {
                resultCharset = Charset.forName("UTF-16");
            }
            else
            {
                resultCharset = Charset.forName(EncodingUtils.DEFAULT_ENCODING);
            }
        }
        return resultCharset;
    }
860219
@Pure
	@Inline(value = "Base64Coder.encode($1, ($1).length)", imported = {Base64Coder.class})
	public static char[] encode(byte[] in) {
		return encode(in, in.length);
	}
1046597
private String encodeBase64(byte[] bytes) {
        Objects.requireNonNull(bytes, Required.BYTES.toString());
        return org.apache.commons.codec.binary.Base64.encodeBase64String(bytes);
    }
983778
def _base64_encode(self, string_to_encode):
        
        try:
            # python 2
            return base64.b64encode(string_to_encode)
        except TypeError:
            # python 3
            encoding = sys.getdefaultencoding()
            base64_bytes = base64.b64encode(bytes(string_to_encode, encoding))
            return base64_bytes.decode(encoding)
1071425
public static byte[] getBytes(String string, String encoding) {
        try {
            return string.getBytes(encoding);
        } catch(UnsupportedEncodingException e) {
            throw new IllegalArgumentException(encoding + " is not a known encoding name.", e);
        }
    }
454345
public static String inputStreamToString(InputStream x,
            String encoding) throws IOException {

        InputStreamReader in        = new InputStreamReader(x, encoding);
        StringWriter      writer    = new StringWriter();
        int               blocksize = 8 * 1024;
        char[]            buffer    = new char[blocksize];

        for (;;) {
            int read = in.read(buffer);

            if (read == -1) {
                break;
            }

            writer.write(buffer, 0, read);
        }

        writer.close();

        return writer.toString();
    }
723622
static public byte[] decode(String encoded) {
		if (encoded == null)
			return null;
		int lengthData = encoded.length();
		if (lengthData % 2 != 0)
			return null;

		char[] binaryData = encoded.toCharArray();
		int lengthDecode = lengthData / 2;
		byte[] decodedData = new byte[lengthDecode];
		byte temp1, temp2;
		char tempChar;
		for (int i = 0; i < lengthDecode; i++) {
			tempChar = binaryData[i * 2];
			temp1 = (tempChar < BASELENGTH) ? hexNumberTable[tempChar] : -1;
			if (temp1 == -1)
				return null;
			tempChar = binaryData[i * 2 + 1];
			temp2 = (tempChar < BASELENGTH) ? hexNumberTable[tempChar] : -1;
			if (temp2 == -1)
				return null;
			decodedData[i] = (byte) ((temp1 << 4) | temp2);
		}
		return decodedData;
	}
333442
public static String uncompressString(byte[] input, String encoding)
            throws IOException,
            UnsupportedEncodingException
    {
        byte[] uncompressed = uncompress(input);
        return new String(uncompressed, encoding);
    }
83990
public static byte[] gzipCompress(String str, String encoding) {
		if (str == null || str.length() == 0) {
			return null;
		}
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		GZIPOutputStream gzip;
		try {
			gzip = new GZIPOutputStream(out);
			gzip.write(str.getBytes(encoding));
			gzip.close();
		} catch (IOException e) {
		}
		return out.toByteArray();
	}
77160
private static String getBase64EncodedString(String str) {
    ByteBuf byteBuf = null;
    ByteBuf encodedByteBuf = null;
    try {
      byteBuf = Unpooled.wrappedBuffer(str.getBytes(StandardCharsets.UTF_8));
      encodedByteBuf = Base64.encode(byteBuf);
      return encodedByteBuf.toString(StandardCharsets.UTF_8);
    } finally {
      // The release is called to suppress the memory leak error messages raised by netty.
      if (byteBuf != null) {
        byteBuf.release();
        if (encodedByteBuf != null) {
          encodedByteBuf.release();
        }
      }
    }
  }
410603
private static String encodeBase64(final byte[] buffer) {
        final int l = buffer.length;
        final char[] out = new char[l << 1];
        int j = 0;
        for (int i = 0; i < l; i++) {
            out[j++] = DIGITS[(0xF0 & buffer[i]) >>> 4];
            out[j++] = DIGITS[0x0F & buffer[i]];
        }
        return String.copyValueOf(out);
    }
499875
public final String encode(byte[] bytes, int off, int len) {
    checkNotNull(bytes);
    checkPositionIndexes(off, off + len, bytes.length);
    CharOutput result = stringBuilderOutput(maxEncodedSize(len));
    ByteOutput byteOutput = encodingStream(result);
    try {
      for (int i = 0; i < len; i++) {
        byteOutput.write(bytes[off + i]);
      }
      byteOutput.close();
    } catch (IOException impossible) {
      throw new AssertionError("impossible");
    }
    return result.toString();
  }
804578
static String base64(byte[] data) {
        ByteBuf encodedData = Unpooled.wrappedBuffer(data);
        ByteBuf encoded = Base64.encode(encodedData);
        String encodedString = encoded.toString(CharsetUtil.UTF_8);
        encoded.release();
        return encodedString;
    }
1039718
private static String decodeString(ByteBuffer src) throws CharacterCodingException
    {
        // the decoder needs to be reset every time we use it, hence the copy per thread
        CharsetDecoder theDecoder = decoder.get();
        theDecoder.reset();

        final CharBuffer dst = CharBuffer.allocate(
                (int) ((double) src.remaining() * theDecoder.maxCharsPerByte()));

        CoderResult cr = theDecoder.decode(src, dst, true);
        if (!cr.isUnderflow())
            cr.throwException();

        cr = theDecoder.flush(dst);
        if (!cr.isUnderflow())
            cr.throwException();

        return dst.flip().toString();
    }