Java压缩类库的使用 2.JDK中的打包、压缩类库
inkfish原创,请勿商业性质转载,转载请注明来源(http://blog.csdn.net/inkfish)。
这里忽略了jar,因为jar实质上属于zip压缩。(来源:http://blog.csdn.net/inkfish)
JDK ZLIB压缩:(来源:http://blog.csdn.net/inkfish)
package study.inkfish.compress;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
public class JdkZLIBCompress extends Compress {
@Override
protected void doCompress(File srcFile, File destFile) throws IOException {
OutputStream out = null;
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(srcFile), bufferLen);
out = new DeflaterOutputStream(new BufferedOutputStream(new FileOutputStream(destFile), bufferLen));
IOUtils.copy(is, out);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(out);
}
}
@Override
protected void doDecompress(File srcFile, File destDir) throws IOException {
InputStream is = null;
OutputStream os = null;
try {
File destFile = new File(destDir, FilenameUtils.getBaseName(srcFile.toString()));
is = new InflaterInputStream(new BufferedInputStream(new FileInputStream(srcFile), bufferLen));
os = new BufferedOutputStream(new FileOutputStream(destFile), bufferLen);
IOUtils.copy(is, os);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
}
JDK ZIP压缩(仅适用于压缩一个文件):(来源:http://blog.csdn.net/inkfish)
package study.inkfish.compress;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOExcep
相关文档:
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
最近项目中遇到了上移下移操作的一个操作,以前也看到过,但一直没有去研究过,这次项目中遇到了,也就去研究了一把,其实实现原理也挺简单的,说白了就是
要记录数据库里的要进行排序表的总记录数量,然后根据循环的次数,多写几个隐藏变量,进行上移下移操作的时候进行判断就可以了。
&n ......
反射、Proxy和元数据是Java最强的三个特征,再加上CGLib (Code Generation Library)
和ASM,使得Java虽然没有Ruby,Python般后生可畏,一样能做出强悍的框架。
Proxy
可以看作是微型的AOP,明白提供了在继承和委托之外的第三个代码封装途径,只要有足够的想象力,可 ......
一:J2SE 面向对象-封装、继承、多态
内存的分析
递归
集合类、泛型、自动打包与解包、Annotation
IO
多线程、线程同步
TCP/UDP
AWT、事件模型、匿名类
正则表达式
反射机制
2:数据库(Oracle或者MySQL)
SQL语句
多表连接,内外连接, 子查询等
管理表、视图、索引、序列、约束等
树状结构存储
存储过 ......
以rhino中执行QQ邮箱的safeauth.js为例
js代码地址:http://res.qqmail.com/zh_CN/htmledition20091127/js/safeauth.js
(1)导入相应类
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import com.sun.phobos.script.javascript.RhinoScriptEngineFactory;
(2)解析JS
ScriptEngine ......