cancel
Showing results for 
Search instead for 
Did you mean: 

ZIP File has damaged contents - Multiple file download

Amey-Mogare
Contributor
0 Kudos

Hi,

I am using ZIP API in Web Dynpro JAVA for multiple file download scenario.

Issue:--->

Some files are not opening correctly after unzipping the ZIP file.

Example-1: some PDF files gives out message that " "

Example-2: Also, a JPG file shows only upper half of the image.

So in all, the content of generated ZIP file are damaged.

Any idea why this is happening?

Thanks & regards,

Amey

Accepted Solutions (0)

Answers (2)

Answers (2)

Amey-Mogare
Contributor
0 Kudos

It worked with readFully(byte[] b) method of DataInputStream.

Following code has to be used to read & fill up byte[] :-


DataInputStream l_dis = new DataInputStream(l_inputStream);

l_dis.readFully(l_byteArray);

Amey-Mogare
Contributor
0 Kudos

And this is the code I'm using:-

Unzipped PDF files give this error --> There was an error opening this document. The file is damaged and could not be repaired


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();

Edited by: Amey Mogare on Mar 30, 2010 7:49 AM