Base85又名ASCII85 java项目 [英] Base85 aka ASCII85 java projects

查看:427
本文介绍了Base85又名ASCII85 java项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道除 com.idataconnect.lib.ascii85codec 以外的其他任何内容 org.apache.commons.codec.binary.Base64 class?

Does anyone know about any other than com.idataconnect.lib.ascii85codec java projects that do something like org.apache.commons.codec.binary.Base64 class?

推荐答案

我发现这个项目似乎可以解决问题:
http://pdfbox.apache .org / downloads.html#recent

I found this project that seems to do the trick: http://pdfbox.apache.org/downloads.html#recent

以下类编码和解码。我们非常欢迎代码评论和建议:

Following class encodes and decodes. Code reviews and suggestions are very welcome:

 import org.apache.pdfbox.io.ASCII85InputStream;
 import org.apache.pdfbox.io.ASCII85OutputStream;

 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;



 public class Ascii85Coder {

 public static byte[] decodeAscii85StringToBytes(String ascii85) {
    ArrayList<Byte> list = new ArrayList<Byte>();
    ByteArrayInputStream in_byte = null;
    try {
        in_byte = new ByteArrayInputStream(ascii85.getBytes("ascii"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    ASCII85InputStream in_ascii = new ASCII85InputStream(in_byte);
    try {
        int r ;
        while ((r = in_ascii.read()) != -1) {
            list.add((byte) r);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    byte[] bytes = new byte[list.size()];
    for (int i = 0; i < bytes.length; i++) {
        bytes[i] = list.get(i);
    }
    return bytes;
}


public static String encodeBytesToAscii85(byte[] bytes) {
    ByteArrayOutputStream out_byte = new ByteArrayOutputStream();
    ASCII85OutputStream  out_ascii = new ASCII85OutputStream(out_byte);

    try {
        out_ascii.write(bytes);
        out_ascii.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String res = "";
    try {
        res = out_byte.toString("ascii");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return res;
}
}

这篇关于Base85又名ASCII85 java项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆