I want to be able to add some files (java.sql.Blob) to a ZIP file in a servlet. At this moment I am able to create the ZIP file, but when opening the ZIP file it´s empty?
Below you see some of my code. I get the files from Blob values:
I guess the problem is my for loop?! I appreciate any help...
Without looking into this in too much depth, it looks like you are writing the contents of the bytearray to the response in line 31. And the bytearray is being filled from in at line 29. in is defined in line 21 as the binary stream from the Blob itself. So it looks to me like your code should be sending the raw blob data to the client - not a zipfile.
Of course there is some other problem with the code if you are getting a zero byte zipfile - I have not looked at what that might be. If the file the client receives does contain data, just is not a zipfile, try changing the extension so you can see if it contains the data you think should be in the zipfile.
Just tried a simple test case for myself, and tested it on my computer:
Although I am just using a file as my input stream in this case, the theory should be the same. I am leaving the writing of the servlet response up to the ZipOutputStream. All I do is add data to the ZipOutputStream.