Hello all,
I get an OutOfMemoryError when accessing large ZipEntry(ies) in a ZIP file (using java.util.zip). It happens when trying to get the input stream. I can go through small entries and grab the input streams, and inflate the files inside, but if I hit a large file, it blows up.
Example:
... code before this....
if (!entry.isDirectory())
{
try
{
**************** blows up on this next line ******************
InputStream tempInputStream = zipFile.getInputStream(entry);
BufferedInputStream is = new BufferedInputStream(tempInputStream);
int currentByte;
// establish buffer for writing file
byte data[] = new byte[BUFFER];
// write the current file to disk
FileOutputStream fos = new FileOutputStream(destFile);
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
// read and write until last byte is encountered
long totalBytes = 0;
long lastPrinted = 0;
Date startTime = new Date();
while ((currentByte = is.read(data, 0, BUFFER)) != -1)
{
totalBytes += BUFFER;
if ((totalBytes) > (lastPrinted + (ONE_HUNDRED_K * 3)))
{
System.out.println("extracted... " + totalBytes);
lastPrinted = totalBytes;
}
dest.write(data, 0, currentByte);
}
dest.flush();
dest.close();
is.close();
... more code follows this ...
I'm guessing that the getInputStream() must read the entire file into memory somehow, but I'm not a
Java Guru. I don't know how I can unzip large files since the getInputStream() method doesn't take buffer sizes as arguments.
Any ideas would be greatly appreciated.
Thanks,
Garret