在解压gz文件时,如果直接用java.util.zip.GZIPInputStream来处理问题只能解压很少一部分内容,通过类MultiMemberGZIPInputStream 可以完全解压一个gz文件。
来源:互联网 发布:陕西旅游实时数据 编辑:程序博客网 时间:2024/06/05 09:47
在解压gz文件时,如果直接用java.util.zip.GZIPInputStream来处理问题只能解压很少一部分内容,通过类MultiMemberGZIPInputStream 可以完全解压一个gz文件。 public class MultiMemberGZIPInputStream extends GZIPInputStream { public MultiMemberGZIPInputStream(InputStream in, int size) public MultiMemberGZIPInputStream(InputStream in) throws IOException { private MultiMemberGZIPInputStream(MultiMemberGZIPInputStream parent) private MultiMemberGZIPInputStream(MultiMemberGZIPInputStream parent, private MultiMemberGZIPInputStream parent; private MultiMemberGZIPInputStream child; private int size; private boolean eos; public int read(byte[] inputBuffer, int inputBufferOffset, if (eos) { int charsRead = super.read(inputBuffer, inputBufferOffset, MultiMemberGZIPInputStream child; } 应用示例: try { FileInputStream fin = new FileInputStream(gzPath); MultiMemberGZIPInputStream MmGz = new MultiMemberGZIPInputStream(fin); byte[] buf = new byte[1024]; nnumber = MmGz.read(buf, 0, buf.length); while (nnumber != -1) { fout.write(buf, 0, nnumber); } } catch (Exception e) {
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.util.zip.GZIPInputStream;
throws IOException {
// Wrap the stream in a PushbackInputStream...
super(new PushbackInputStream(in, size), size);
this.size = size;
}
// Wrap the stream in a PushbackInputStream...
super(new PushbackInputStream(in, 1024));
this.size = -1;
}
throws IOException {
super(parent.in);
this.size = -1;
this.parent = parent.parent == null ? parent : parent.parent;
this.parent.child = this;
}
int size) throws IOException {
super(parent.in, size);
this.size = size;
this.parent = parent.parent == null ? parent : parent.parent;
this.parent.child = this;
}
int inputBufferLen) throws IOException {
return -1;
}
if (this.child != null)
return this.child.read(inputBuffer, inputBufferOffset,
inputBufferLen);
inputBufferLen);
if (charsRead == -1) {
// Push any remaining buffered data back onto the stream
// If the stream is then not empty, use it to construct
// a new instance of this class and delegate this and any
// future calls to it...
int n = inf.getRemaining() - 8;
if (n > 0) {
// More than 8 bytes remaining in deflater
// First 8 are gzip trailer. Add the rest to
// any un-read data...
((PushbackInputStream) this.in).unread(buf, len - n, n);
} else {
// Nothing in the buffer. We need to know whether or not
// there is unread data available in the underlying stream
// since the base class will not handle an empty file.
// Read a byte to see if there is data and if so,
// push it back onto the stream...
byte[] b = new byte[1];
int ret = in.read(b, 0, 1);
if (ret == -1) {
eos = true;
return -1;
} else
((PushbackInputStream) this.in).unread(b, 0, 1);
}
if (this.size == -1)
child = new MultiMemberGZIPInputStream(this);
else
child = new MultiMemberGZIPInputStream(this, this.size);
return child.read(inputBuffer, inputBufferOffset, inputBufferLen);
} else
return charsRead;
}
int nnumber;
FileOutputStream fout = new FileOutputStream(topath);
nnumber = MmGz.read(buf, 0, buf.length);
MmGz.close();
fout.close();
fin.close();
e.printStackTrace();
}
- 在解压gz文件时,如果直接用java.util.zip.GZIPInputStream来处理问题只能解压很少一部分内容,通过类MultiMemberGZIPInputStream 可以完全解压一个gz文件。
- java解压gz文件
- zip,jar,tar.gz无需解压读取文件内容
- linux解压 .gz 文件
- 解压.tar.gz文件
- 解压.tar.gz文件
- 解压*.tar.gz文件
- 解压cpio.gz文件
- 解压cpio.gz文件
- linux 解压gz文件
- 如何解压.gz文件
- .cpio.gz文件解压
- 解压.gz文件
- cpio.gz文件解压
- 解压tar.gz文件
- 解压cpio.gz文件
- gz文件合并解压
- C#解压GZ文件
- 编译《DirectShow实务精选》示例可能发生的问题及解决办法
- 关于函数句柄(@)的相关内容
- 转载 MTK存储系统相关
- c++笔试题汇总
- MultiMemberGZIPInputStream MmGz = new MultiMemberGZIPInputStream(fin);
- 在解压gz文件时,如果直接用java.util.zip.GZIPInputStream来处理问题只能解压很少一部分内容,通过类MultiMemberGZIPInputStream 可以完全解压一个gz文件。
- 转:otsu自适应阈值分割的算法描述和opencv实现,及其在肤色检测中的应用
- 网络数据自动备份系统的设计思路
- 实现爆破的几种方法
- 七步法解决问题
- SQL Server 无法连接 错误
- zoj1457_Prime Ring Problem
- strtok与strtok_r源码
- 一周Qt使用小结