T
Tony O'Bryan
I'm trying to read a Zip file, and am having problems. First, here is my
process:
1) Create a ZipFile object based on a filename.
2) Get a ZipEntry object based on a filename in the archive.
3) Create an Inflator object with nowrap true. Removing true generates an
"unknown compression type" error.
4) Get an InputStream object from the ZipFile object, based on the ZipEntry.
5) Read the compressed data via the InputStream object.
6) Set the Inflator object's input to the compressed data.
7) Call the Inflator's inflate method to get decompressed data.
Steps 1 through 6 work fine, but my program fails at step 7. I always get
"java.util.zip.DataFormatException: invalid block type" at the call to
inflate. Here's the source code to go along with the problem:
========================================================
ZipFile zipFile = new ZipFile(args[0]);
ZipEntry entry = zipFile.getEntry(args[1]);
Inflater inflater = new Inflater(true);
InputStream input = zipFile.getInputStream(entry);
long lCompressedSize = entry.getCompressedSize();
byte [] baCompressed = new byte[(int)lCompressedSize];
byte [] baUncompressed = new byte[(int)entry.getSize()];
int nBytesRead;
nBytesRead = input.read(baCompressed);
inflater.setInput(baCompressed,0,nBytesRead);
inflater.inflate(baUncompressed);
=========================================================
I have confirmed results at each stage, up to and including reading the
compressed data into baCompressed.
Is there some gotcha in Java's Zip handling that I'm not aware of?
process:
1) Create a ZipFile object based on a filename.
2) Get a ZipEntry object based on a filename in the archive.
3) Create an Inflator object with nowrap true. Removing true generates an
"unknown compression type" error.
4) Get an InputStream object from the ZipFile object, based on the ZipEntry.
5) Read the compressed data via the InputStream object.
6) Set the Inflator object's input to the compressed data.
7) Call the Inflator's inflate method to get decompressed data.
Steps 1 through 6 work fine, but my program fails at step 7. I always get
"java.util.zip.DataFormatException: invalid block type" at the call to
inflate. Here's the source code to go along with the problem:
========================================================
ZipFile zipFile = new ZipFile(args[0]);
ZipEntry entry = zipFile.getEntry(args[1]);
Inflater inflater = new Inflater(true);
InputStream input = zipFile.getInputStream(entry);
long lCompressedSize = entry.getCompressedSize();
byte [] baCompressed = new byte[(int)lCompressedSize];
byte [] baUncompressed = new byte[(int)entry.getSize()];
int nBytesRead;
nBytesRead = input.read(baCompressed);
inflater.setInput(baCompressed,0,nBytesRead);
inflater.inflate(baUncompressed);
=========================================================
I have confirmed results at each stage, up to and including reading the
compressed data into baCompressed.
Is there some gotcha in Java's Zip handling that I'm not aware of?