- public class Base64 {
- public static byte[] encode(byte[] b) throws Exception {
- ByteArrayOutputStream baos = null;
- OutputStream b64os = null;
- try {
- baos = new ByteArrayOutputStream();
- b64os = MimeUtility.encode(baos, "base64");
- b64os.write(b);
- b64os.close();
- return baos.toByteArray();
- } catch (Exception e) {
- throw new Exception(e);
- } finally {
- try {
- if (baos != null) {
- baos.close();
- baos = null;
- }
- } catch (Exception e) {
- }
- try {
- if (b64os != null) {
- b64os.close();
- b64os = null;
- }
- } catch (Exception e) {
- }
- }
- }
来源: http://www.bubuko.com/infodetail-3042559.html