Question

In Java, I am accepting an input stream from a webpage which happens to be a zip file. I would like to unzip the file before saving it to the disk. However, my zipInputStream.getNextEntry throws the following error:

"java.util.zip.ZipException: only DEFLATED entries can have EXT descriptor"

Here is the code I am using. This first part works fine:

URL url = new URL ("http://"+ipAddress+"/axis-cgi/record/download.cgi?diskid=SD_DISK&recordingid="+recordingID);
byte[] encodedBytes = Base64.encodeBase64((username+":"+password).getBytes());
String encoding = new String (encodedBytes);

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoInput (true);
connection.setRequestProperty  ("Authorization", "Basic " + encoding);
connection.connect();

InputStream inputStream = connection.getInputStream();

This is the part of my code that is throwing the error (in the 'while' statement below). Note that unpack() writes to a file.

ZipInputStream zipStream = new ZipInputStream(inputStream);
ZipEntry zipEntry = null;
while ((zipEntry = zipStream.getNextEntry()) != null) {
    File destinationFile = new File("C:/Users/user1/Documents/folder1/test", zipEntry.getName());
    unpackEntry(destinationFile, zipStream);
}
zipStream.close();

What is the error saying only deflated entries can have an EXT? Does this mean that the file I'm receiving is not actually a zip (ie it is a regular folder)? I tried saving the InputStream directly using File, but the result is a file that my computer does not recognize.

Was it helpful?

Solution

Per the suggestion of c.s., I reviewed this thread. how to unzip an encrypted ODT OpenDocument in Java. To summarize, ZipInputStream has problems unzipping files that are in a zip file but are not compressed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top