- 浏览: 203454 次
- 性别:
- 来自: 北京
最新评论
-
guoranaccp:
太帅了
Base64Encoder源码 -
xsw331:
...
javacsv导出 -
rock1103:
不错啊,中文也可以
javacsv导出 -
lyfi:
...
Base64Encoder源码 -
chengpeinishi:
亲们,资源可用哦。
javacsv导出
Base64Encoder源码
- 博客分类:
- Java
import java.io.*; /******************************************************************************* * A class to encode Base64 streams and strings. See RFC 1521 section 5.2 for * details of the Base64 algorithm. * <p> * This class can be used for encoding strings: <blockquote> * * <pre> * String unencoded = "webmaster:try2gueSS"; * String encoded = Base64Encoder.encode(unencoded); * </pre> * * </blockquote> or for encoding streams: <blockquote> * * <pre> * OutputStream out = new Base64Encoder(System.out); * </pre> * * </blockquote> * * @author <b>Jason Hunter</b>, Copyright © 2000 * @version 1.2, 2002/11/01, added encode(byte[]) method to better handle binary * data (thanks to Sean Graham) * @version 1.1, 2000/11/17, fixed bug with sign bit for char values * @version 1.0, 2000/06/11 */ public class Base64Encoder extends FilterOutputStream { private static final char[] chars = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; private int charCount; private int carryOver; /*************************************************************************** * Constructs a new Base64 encoder that writes output to the given * OutputStream. * * @param out * the output stream */ public Base64Encoder(OutputStream out) { super(out); } /*************************************************************************** * Writes the given byte to the output stream in an encoded form. * * @exception IOException * if an I/O error occurs */ public void write(int b) throws IOException { // Take 24-bits from three octets, translate into four encoded chars // Break lines at 76 chars // If necessary, pad with 0 bits on the right at the end // Use = signs as padding at the end to ensure encodedLength % 4 == 0 // Remove the sign bit, // thanks to Christian Schweingruber <chrigu@lorraine.ch> if (b < 0) { b += 256; } // First byte use first six bits, save last two bits if (charCount % 3 == 0) { int lookup = b >> 2; carryOver = b & 3; // last two bits out.write(chars[lookup]); } // Second byte use previous two bits and first four new bits, // save last four bits else if (charCount % 3 == 1) { int lookup = ((carryOver << 4) + (b >> 4)) & 63; carryOver = b & 15; // last four bits out.write(chars[lookup]); } // Third byte use previous four bits and first two new bits, // then use last six new bits else if (charCount % 3 == 2) { int lookup = ((carryOver << 2) + (b >> 6)) & 63; out.write(chars[lookup]); lookup = b & 63; // last six bits out.write(chars[lookup]); carryOver = 0; } charCount++; // Add newline every 76 output chars (that's 57 input chars) if (charCount % 57 == 0) { out.write('\n'); } } /*************************************************************************** * Writes the given byte array to the output stream in an encoded form. * * @param buf * the data to be written * @param off * the start offset of the data * @param len * the length of the data * @exception IOException * if an I/O error occurs */ public void write(byte[] buf, int off, int len) throws IOException { // This could of course be optimized for (int i = 0; i < len; i++) { write(buf[off + i]); } } /*************************************************************************** * Closes the stream, this MUST be called to ensure proper padding is * written to the end of the output stream. * * @exception IOException * if an I/O error occurs */ public void close() throws IOException { // Handle leftover bytes if (charCount % 3 == 1) { // one leftover int lookup = (carryOver << 4) & 63; out.write(chars[lookup]); out.write('='); out.write('='); } else if (charCount % 3 == 2) { // two leftovers int lookup = (carryOver << 2) & 63; out.write(chars[lookup]); out.write('='); } super.close(); } /*************************************************************************** * Returns the encoded form of the given unencoded string. The encoder uses * the ISO-8859-1 (Latin-1) encoding to convert the string to bytes. For * greater control over the encoding, encode the string to bytes yourself * and use encode(byte[]). * * @param unencoded * the string to encode * @return the encoded form of the unencoded string */ public static String encode(String unencoded) { byte[] bytes = null; try { bytes = unencoded.getBytes("8859_1"); } catch (UnsupportedEncodingException ignored) { } return encode(bytes); } /*************************************************************************** * Returns the encoded form of the given unencoded string. * * @param bytes * the bytes to encode * @return the encoded form of the unencoded string */ public static String encode(byte[] bytes) { ByteArrayOutputStream out = new ByteArrayOutputStream((int) (bytes.length * 1.37)); Base64Encoder encodedOut = new Base64Encoder(out); try { encodedOut.write(bytes); encodedOut.close(); return out.toString("8859_1"); } catch (IOException ignored) { return null; } } public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java com.oreilly.servlet.Base64Encoder fileToEncode"); return; } Base64Encoder encoder = null; BufferedInputStream in = null; try { encoder = new Base64Encoder(System.out); in = new BufferedInputStream(new FileInputStream(args[0])); byte[] buf = new byte[4 * 1024]; // 4K buffer int bytesRead; while ((bytesRead = in.read(buf)) != -1) { encoder.write(buf, 0, bytesRead); } } finally { if (in != null) in.close(); if (encoder != null) encoder.close(); } } }
发表评论
-
eclipse axis2 插件 安装 link方式
2012-05-15 16:59 1790插件下载地址: http://www.apache.o ... -
JRuby初始安装与使用
2012-03-06 10:28 1120JRUBY的下载:http://dist.codehaus.o ... -
input type=file 标签禁止让用户手动输入
2012-02-21 14:08 952<input name="filePat ... -
通过Mysql语句得到mysql安装路径
2012-01-07 13:07 9021、通过Mysql语句得到mysql安装路径: sel ... -
Apache Ant 环境搭建
2012-01-07 13:05 1083Apache Ant 下载地址:http://ant.apac ... -
Base64Decoder源码
2011-11-09 08:55 2529import java.io.*; /****** ... -
JS和Java验证IP合法
2011-11-01 17:32 2361/* JS验证IP是否合法 */ function i ... -
修改Mysql启动路径
2011-11-01 17:31 1874修改Mysql启动路径 首先在服务中停止MySq ... -
Mysql提速
2011-09-21 16:55 1414因数据较大,导致执行速度慢,同事帮我优化一下,果然见效。 ... -
更换SVN用户
2011-09-21 16:25 756修改eclipse中的svn用户 1. 查看你的 ... -
Mac下JDK路径
2011-08-26 22:49 1198/System/Library/Java/JavaVirtua ... -
web.xml中load-on-startup标签
2011-08-11 10:54 810在servlet的配置当中,<load-on-st ... -
同时启动多个Tomcat服务器
2011-08-09 09:17 877所用Tomcat服务器都为zip版,非安装版。以两个为例:安装 ... -
String StringBuffer StringBuilder区别
2011-07-30 11:24 764String 字符串常量StringB ... -
java中访问修饰符public,protected,private,friendly
2011-07-30 11:21 10141)public: 表明该数据成员、函数都是对多有用户开发 ... -
存储过程的优点
2011-07-26 01:38 988在性能方面,存储过程的优点: 1、预编译,存储过程预先编译好放 ... -
数据库视图的优点与缺点
2011-07-26 01:34 1707在程序设计的时候必须先了解视图的优缺点,这样可以扬长避短,视图 ... -
eclipse配置tomcat7
2011-05-31 12:32 1003图解如下: 修改服务器启动所需的jar包 即to ... -
Linux下Java环境的JDK+Tomcat+Mysql安装和配置
2011-05-26 13:29 999CentOS5.4下安装JDK 1、 ... -
tomcat配置管理用户名密码
2011-05-26 11:01 1593tomcat默认是将用户是注释的 配置文件在根目 ...
相关推荐
sun.misc.BASE64Encoder源码及jar包
1.包含 sun.misc.BASE64加解密源码和jar【源码仅仅几个类而已】 2.完整的sun.misc.BASE64类【直接项目引用即可】
BASE64Encoder.java和BASE64Decoder.java类的源代码,可以再android SDK 与java JDK下无差错信息通信
BASE64Encoder及BASE64Decoder的源码
sun.misc.BASE64Encoder 的源码及JAR包
NULL 博文链接:https://yangxiutian.iteye.com/blog/1739786
import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; BASE64加密与解密使用的jar包
base64是网络传输中常用的编码形式.由于其非常好地支持ascii码,且可以很容易地与任意的编码形式相互转换,所以受到大多数网络编程者的青睐。
BASE64Encoder encoder = new BASE64Encoder(); return encoder.encode(md.digest(str.getBytes("utf-8"))); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } }
解决android无法使用sun.misc.CharacterDecoder,添加了rt.jar也不行。 然后本人就寻找了其六个...BASE64Encoder.java CEFormatException.java CEStreamExhausted.java CharacterDecoder.java CharacterEncoder.java
Andriod Studio(java):Jackson的应用、Handler多线程间通信、自定义Adapter、Fontawesome在Android的应用、sun.misc.BASE64Encoder在Andriod的应用、 共有:Socket的通信、Base64加密与解密、MD5码验证、分包思想...
换到burp2020后,这款工具就用不了了,因为原工具Base64编码是使⽤JDK⾥sun.misc套件下的BASE64Encoder和BASE64Decoder这两个类,但是burp2020只能运行在java8环境下,JDK1.8已经取消了这个编码方法,所以burp2020就...
Cknife源码从 Chora && MelodyZX 的GitHub 上获得,本人对涉及BASE64ENCODER的代码做了修改以适应java9版本。 下载后用eclipse导入项目(project),编译运行src/com/ms509/ui下的Cknife.java即可。
Android登录各大网站微博OAuth认证实例,附完整实例源代码。...实现方面,在代码中初始化各门户网站微博的认证信息、设置当前操作的weibo,不同的weibo请求存在着差异,在发送数据的时候进行Base64Encoder加密。
包括一些语音编码器, Hex, Base64, 以及URL encoder. Collections Commons-Collections 提供一个类包来扩展和增加标准的 Java Collection框架 Configuration Commons-Configuration 工具对各种各式的配置和参考...
基于机器学习与深度学习不同算法(crf_HMM_gru_Transformer等)的中文分词实现python源码+说明.zip 【资源介绍】 该项目是个人毕设项目,答辩评审分达到95分,代码都经过调试测试,确保可以运行!欢迎下载使用,可用于...
2. 我们目前还没有完全拆解分析ERNIE模型的源码及模型结构,暂时不能实现移植到Pytorch上用bert-base-chinese实现相似的功能。 API实现 我们使用了Flask轻量化Web框架实现了简单的Web API接口化。将模型导出为静态...
-4 better compression but 3.5X slower, uses 64 MB -5 slightly better compression, 6X slower than -3, uses 154 MB -6 about like -5, uses 202 MB memory -7 to -9 use 404 MB, 808 MB, 1616 MB, about ...
Some minor bugs that I don‘t remember fixed.- Added MIME-compliant base64 support (not for use by now). Added examples.0.9.2.1b- Fixed a bug when send a mail and the first line disappear (thanks to ...