首页 > 编程语言 > 详细

Java determine uncompressed size of gzipped file

时间:2014-05-06 18:25:53      阅读:408      评论:0      收藏:0      [点我收藏+]

If you want to determine the uncompressed size of a gzip file from within a program, you can extract to original file size from the gzip file. This size is stored in the last 4 bytes of the file. This will only provide the correct value if the compressed file was smaller than 4 Gb.

To extract this information and convert it to something useful in your Java program.

RandomAccessFile raf = new RandomAccessFile(file, "r");
raf.seek(raf.length() - 4);
int b4 = raf.read();
int b3 = raf.read();
int b2 = raf.read();
int b1 = raf.read();
int val = (b1 << 24) | (b2 << 16) + (b3 << 8) + b4;
raf.close();

The original size of the compressed file will now be available in the val variable in bytes.

http://www.abeel.be/wiki/Java_determine_uncompressed_size_of_gzipped_file

 

 

Java determine uncompressed size of gzipped file,布布扣,bubuko.com

Java determine uncompressed size of gzipped file

原文:http://www.cnblogs.com/lizhongchen/p/3712068.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!