Hi,
I am using ZIP API in multiple file download scenario.
Some files are not opening correctly after unzipping the ZIP file.
For Example-1: some PDF files gives out message that "*There was an error opening this document.
The file is damaged and could not be repaired*"
Example-2: Also, a JPG files shows only upper half of the image.
The content of generated ZIP file are damaged.
Any idea why this is happening?
This is the code I am using:-
//Actually this is SAP Web Dynpro JAVA code.. So ignore some Web Dynpro code lines in between.
//Otherwise, its just the normal JAVA code
ByteArrayOutputStream l_baos = new ByteArrayOutputStream();
ZipOutputStream l_zos = new ZipOutputStream(l_baos);
for(int i = 0; i < l_int_NodeSize; i++){
g_SearchOutputEle = g_SearchOutputNode.getCtx_vn_SearchOutputElementAt(i);
java.net.URL url = new URL(g_SearchOutputEle.getFileUrl());
java.net.URLConnection urlConnection = url.openConnection();
java.io.InputStream inputStream = url.openStream();
int arraySize = urlConnection.getContentLength();
byte[] byteArray = new byte[arraySize];
DataInputStream dis = new DataInputStream(inputStream);
dis.read(byteArray);
ZipEntry zipEntry = new ZipEntry("Name-"+i);
zipEntry.setSize(byteArray.length);
zos.putNextEntry(zipEntry);
zos.write(byteArray);
zos.closeEntry();
}
zos.close();
byte[] byteOutArray = baos.toByteArray();
IWDResource resource = WDResourceFactory.createResource(byteOutArray, "Downloads.zip",WDWebResourceType.UNKNOWN);
String urlString = resource.getUrl(WDFileDownloadBehaviour.ALLOW_SAVE.ordinal());
IWDWindow win_MultiFileWindow = wdComponentAPI.getWindowManager().createNonModalExternalWindow(urlString);
win_MultiFileWindow.setWindowSize(0,0);
win_MultiFileWindow.show();
Thanks and regards,
Amey Mogare