- 浏览: 203446 次
- 性别:
- 来自: 北京
最新评论
-
guoranaccp:
太帅了
Base64Encoder源码 -
xsw331:
...
javacsv导出 -
rock1103:
不错啊,中文也可以
javacsv导出 -
lyfi:
...
Base64Encoder源码 -
chengpeinishi:
亲们,资源可用哦。
javacsv导出
import java.io.*; /******************************************************************************* * A class to decode Base64 streams and strings. See RFC 1521 section 5.2 for * details of the Base64 algorithm. * <p> * This class can be used for decoding strings: <blockquote> * * <pre> * String encoded = "d2VibWFzdGVyOnRyeTJndWVTUw"; * String decoded = Base64Decoder.decode(encoded); * </pre> * * </blockquote> or for decoding streams: <blockquote> * * <pre> * InputStream in = new Base64Decoder(System.in); * </pre> * * </blockquote> * * @author <b>Jason Hunter</b>, Copyright © 2000 * @version 1.1, 2002/11/01, added decodeToBytes() to better handle binary data * (thanks to Sean Graham) * @version 1.0, 2000/06/11 */ public class Base64Decoder extends FilterInputStream { 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', '+', '/' }; // A mapping between char values and six-bit integers private static final int[] ints = new int[128]; static { for (int i = 0; i < 64; i++) { ints[chars[i]] = i; } } private int charCount; private int carryOver; /*************************************************************************** * Constructs a new Base64 decoder that reads input from the given * InputStream. * * @param in * the input stream */ public Base64Decoder(InputStream in) { super(in); } /*************************************************************************** * Returns the next decoded character from the stream, or -1 if end of * stream was reached. * * @return the decoded character, or -1 if the end of the input stream is * reached * @exception IOException * if an I/O error occurs */ public int read() throws IOException { // Read the next non-whitespace character int x; do { x = in.read(); if (x == -1) { return -1; } } while (Character.isWhitespace((char) x)); charCount++; // The '=' sign is just padding if (x == '=') { return -1; // effective end of stream } // Convert from raw form to 6-bit form x = ints[x]; // Calculate which character we're decoding now int mode = (charCount - 1) % 4; // First char save all six bits, go for another if (mode == 0) { carryOver = x & 63; return read(); } // Second char use previous six bits and first two new bits, // save last four bits else if (mode == 1) { int decoded = ((carryOver << 2) + (x >> 4)) & 255; carryOver = x & 15; return decoded; } // Third char use previous four bits and first four new bits, // save last two bits else if (mode == 2) { int decoded = ((carryOver << 4) + (x >> 2)) & 255; carryOver = x & 3; return decoded; } // Fourth char use previous two bits and all six new bits else if (mode == 3) { int decoded = ((carryOver << 6) + x) & 255; return decoded; } return -1; // can't actually reach this line } /*************************************************************************** * Reads decoded data into an array of bytes and returns the actual number * of bytes read, or -1 if end of stream was reached. * * @param buf * the buffer into which the data is read * @param off * the start offset of the data * @param len * the maximum number of bytes to read * @return the actual number of bytes read, or -1 if the end of the input * stream is reached * @exception IOException * if an I/O error occurs */ public int read(byte[] buf, int off, int len) throws IOException { if (buf.length < (len + off - 1)) { throw new IOException("The input buffer is too small: " + len + " bytes requested starting at offset " + off + " while the buffer " + " is only " + buf.length + " bytes long."); } // This could of course be optimized int i; for (i = 0; i < len; i++) { int x = read(); if (x == -1 && i == 0) { // an immediate -1 returns -1 return -1; } else if (x == -1) { // a later -1 returns the chars read so far break; } buf[off + i] = (byte) x; } return i; } /*************************************************************************** * Returns the decoded form of the given encoded string, as a String. Note * that not all binary data can be represented as a String, so this method * should only be used for encoded String data. Use decodeToBytes() * otherwise. * * @param encoded * the string to decode * @return the decoded form of the encoded string */ public static String decode(String encoded) { return new String(decodeToBytes(encoded)); } public static byte[] decodeReturnByte(String encodedStr) { return decodeToBytes(encodedStr); } /*************************************************************************** * Returns the decoded form of the given encoded string, as bytes. * * @param encoded * the string to decode * @return the decoded form of the encoded string */ public static byte[] decodeToBytes(String encoded) { byte[] bytes = null; try { bytes = encoded.getBytes("8859_1"); } catch (UnsupportedEncodingException ignored) { } Base64Decoder in = new Base64Decoder(new ByteArrayInputStream(bytes)); ByteArrayOutputStream out = new ByteArrayOutputStream( (int) (bytes.length * 0.67)); try { byte[] buf = new byte[4 * 1024]; // 4K buffer int bytesRead; while ((bytesRead = in.read(buf)) != -1) { out.write(buf, 0, bytesRead); } out.close(); return out.toByteArray(); } catch (IOException ignored) { return null; } } public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java Base64Decoder fileToDecode"); return; } Base64Decoder decoder = null; try { decoder = new Base64Decoder(new BufferedInputStream(new FileInputStream(args[0]))); byte[] buf = new byte[4 * 1024]; // 4K buffer int bytesRead; while ((bytesRead = decoder.read(buf)) != -1) { System.out.write(buf, 0, bytesRead); } } finally { if (decoder != null) decoder.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 ... -
Base64Encoder源码
2011-11-09 08:56 6205import java.io.*; /****** ... -
JS和Java验证IP合法
2011-11-01 17:32 2361/* JS验证IP是否合法 */ function i ... -
修改Mysql启动路径
2011-11-01 17:31 1873修改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 809在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默认是将用户是注释的 配置文件在根目 ...
相关推荐
BASE64Encoder.java和BASE64Decoder.java类的源代码,可以再android SDK 与java JDK下无差错信息通信
BASE64Encoder及BASE64Decoder的源码
NULL 博文链接:https://yangxiutian.iteye.com/blog/1739786
sun.misc.BASE64Encoder源码及jar包
function Base64ToImage(const base64:string;AImage:TImage):Boolean; function Base64ToImageFile(const base64:string;AImagefile:string):Boolean; function CheckImgTypeBase64(abase64:string):string;
基于java BASE64Decoder 算法实现数据库账号的加密解密的源码
解决android无法使用sun.misc.CharacterDecoder,添加了rt.jar也不行。...BASE64Decoder.java BASE64Encoder.java CEFormatException.java CEStreamExhausted.java CharacterDecoder.java CharacterEncoder.java
import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; BASE64加密与解密使用的jar包
解决android开发时,导入sun.misc.BASE64Decoder错误,自己就提取源码后做的jar包,导入就可用。
Base64 encode/decode
NULL 博文链接:https://orange5458.iteye.com/blog/1139596
换到burp2020后,这款工具就用不了了,因为原工具Base64编码是使⽤JDK⾥sun.misc套件下的BASE64Encoder和BASE64Decoder这两个类,但是burp2020只能运行在java8环境下,JDK1.8已经取消了这个编码方法,所以burp2020就...
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 ...
背景图不生效,改用image或者Base64 执行POST请求异常,将data中的JSON对象格式化为from序列 页面切换的参数接收异常,在onload方法中,默认的参数即使上一页面传过来的Object参数 在使用data-readingItem的时候,...
-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 ...
Dump1090自述文件 转储1090是专门为RTLSDR设备设计的S模式解码器。 主要特点是: 对弱消息的健壮解码,与其他流行的解码器相比,使用mode1090,许多用户观察到范围有所改善。 ... ... 使用24位CRC进行单位纠错。...
常用编码工具类,支持base64,md5,des,crc32 也谈谈技术面试 在C#里把ArrayList转换为Array 或 把Array转换为ArrayList C# 2.0 在.NET 2.0中,让你的组件也可以绑定 .NET20 一种简单的窗口控件UI状态控制方法 翻译MSDN...