易截截图软件、单文件、免安装、纯绿色、仅160KB

Java压缩类库的使用 5.性能检测

  inkfish原创,请勿商业性质转载,转载请注明来源(http://blog.csdn.net/inkfish
)。
  在选择压缩、打包算法的时候,不仅仅要选择算法,还需要选择用哪个实现类库,不同的实现类库实现效率不同,默认压缩比率不同。为了测试JDK、Ant、commons-compress在默认情况下的效率,设计了如下程序:(来源:http://blog.csdn.net/inkfish)
100M大小随机字符串文件生成程序:(来源:http://blog.csdn.net/inkfish)
package study.inkfish.compress;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.RandomStringUtils;
public class CharFileGener {
public static void main(String[] args) throws IOException {
charGener();
}
private static void charGener() throws IOException {
Writer writer = new BufferedWriter(new FileWriter(new File("D:/TestCompress/txt.txt")),
1024 * 1024 * 5);
int max = 1024 * 1024;
String strs = "`1234567890-=~!@#$%^&*()_+qwertyuiop[]\\QWERTYUIOP{}|asdfghjkl;'\":LKJHGFDSAzxcvbnm,./?><MNBVCXZ";
for (int i = 0; i < max; i++) {
writer.write(RandomStringUtils.random(99, strs));
writer.write("\n");
}
IOUtils.closeQuietly(writer);
}
}

上面的代码用于生成随机的半角字符组成的文本文件,大小为100M(1024*1024*100byte)。(来源:http://blog.csdn.net/inkfish)
性能测试程序:(来源:http://blog.csdn.net/inkfish)
package study.inkfish.compress;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
public class TestCompress {
public static void main(String[] args) throws IOException {
File srcFile = new File("D:/TestCompress", "text.txt");
for (int i = 0; i < 3; i++) {//循环测试三遍
doTest(srcFile);
cleanDir(srcFile);
}
}
private static void cleanDir(File srcFile) throws IOException {
FileUtils.deleteDirectory(new Fi


相关文档:

Java NIO API详解

 
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......

Java下的框架编程(5)

 



   反射、Proxy和元数据是Java最强的三个特征,再加上CGLib (Code Generation Library)
和ASM,使得Java虽然没有Ruby,Python般后生可畏,一样能做出强悍的框架。
   Proxy
可以看作是微型的AOP,明白提供了在继承和委托之外的第三个代码封装途径,只要有足够的想象力,可 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号