I create a program that will extract the zip and then insert the files into the database, every so often I get an error
java.lang.Exception: java.io.EOFException: Unexpected end of ZLIB input stream
I cannot pinpoint the reason for this, since the extraction code is almost the same as all other code that you can find on the Internet. My code is as follows:
public void extract(String zipName, InputStream content) throws Exception {
int BUFFER = 2048;
ZipInputStream zis = new ZipInputStream(content);
String containerName = zipName;
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String currentEntry = entry.getName();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte data[] = new byte[BUFFER];
int currentByte;
while ((currentByte = zis.read(data, 0, BUFFER)) != -1) {
baos.write(data, 0, currentByte);
}
baos.flush();
insertZipEntry(baos.toByteArray());
baos.close();
}
catch (Exception e) {
System.out.println("ERROR WITHIN ZIP " + containerName);
}
}
}
source
share