I am testing a framework in which I download zip file trough HTTP Get. I use Apache HttpClient for that. I am having hard time saving a response that is a zip file. I tried just Output Stream pointing to the path that end with ".zip" but it is not working, the zip is invalid. I tried to ZipOuputStream but then it asks for entry, and I don't know the entry. I am trying unzip it as it comes to get the entry then and so far, nothing is working. Here are some variations I've tried so far
** ZipInputStream zipStream = new ZipInputStream(response.getEntity().getContent());
ZipEntry entry = null;
Scanner sc = new Scanner(zipStream);
while ((entry = zipStream.getNextEntry()) != null) {
String entryName = entry.getName();
System.out.println(entryName);
FileOutputStream out = new FileOutputStream(entryName);
byte[] byteBuff = new byte[4096];
int bytesRead = 0;
while ((bytesRead = zipStream.read(byteBuff)) != -1)
{
out.write(byteBuff, 0, bytesRead);
}
out.close();
zipStream.closeEntry();
}
zipStream.close();
**
The above code doesn't see the zipStream.getNextEntry(), it is always null, with or without the Scanner it is same result, Scanner also always returns null.
Or same thing but the beginning being byte array
byte[] bytes = EntityUtils.toByteArray(response.getEntity());
ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(bytes));
Same issue as the above, when I later start processing it with while ((entry = zipStream.getNextEntry()) != null) to get files from it, it is also always null for the next element
or
byte[] bytes = EntityUtils.toByteArray(response.getEntity());
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(filePath));
zos.write(bytes);
In this case there is error that the file requires ZipEntry and I don't know how to obtain it. I've tried with the above code for unziping but the element is always.
FileOutputStream fos = new FileOutputStream(filePath);
response.getEntity().writeTo(fos);
This writes a file but is invalid, I can't open it manually coz it is always giving me an error.
FileOutputStream fos = new FileOutputStream(filePath);
ZipOutputStream zos = new ZipOutputStream(fos);
response.getEntity().writeTo(zos);
This is throwing java.util.zip.ZipException: no current ZIP entry so zip I can open zip in Windows but is empty since it breaks.
But nothing is working so far
EDIT I am not sure what is it relating to but the corrupted file that I am getting through some of the approaches is 757kB while the one I get through swagger is 14,726kB. Is there a limitation on the data transfer for entity?