• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The zip archive is corrupt after download in Java servlet

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i create servlet for create zip file of my database attachment and download,but result is a archive corrupt why? after open file this message recieve: C:\Users...\Downloads\DATA.zip: Unexpected end of archive

 
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abed asghari wrote:


What is fill_of_database?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abed, one suggestion: You are doing two things there, creating a zip archive and sending it as a servlet response. Either of those two things could be the source of your problem, conceivably. So I suggest testing them separately. In particular create the zip archive and write it to a file locally, in plain old Java code and not in a servlet. If that works then try sending the archive as a servlet response.
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Paul, I checked  In particular create the zip archive and write it to a file locally is  correct but after download it will be corrupted
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ron McLeod i checked zip file in server direction is correct but after download is corrupt
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote: Abed, one suggestion: You are doing two things there, creating a zip archive and sending it as a servlet response. Either of those two things could be the source of your problem, conceivably. So I suggest testing them separately. In particular create the zip archive and write it to a file locally, in plain old Java code and not in a servlet. If that works then try sending the archive as a servlet response.


thanks Paul, I checked  In particular create the zip archive and write it to a file locally is  correct but after download it will be corrupted
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show your test code that successfully outputs to a local file?
Just so we can see whether there is some subtle difference.
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Can you show your test code that successfully outputs to a local file?
Just so we can see whether there is some subtle difference.



test for save in server from database that is correct

 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your servlet code you're calling "zos.finish()" and in your local download code you aren't. I doubt that's the subtle difference that Dave was hoping for, though.

Can I suggest that now you have done a local download which is okay and a remote download which is corrupt, that you bring the two together and compare them to see what's different?
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:In your servlet code you're calling "zos.finish()" and in your local download code you aren't. I doubt that's the subtle difference that Dave was hoping for, though.

Can I suggest that now you have done a local download which is okay and a remote download which is corrupt, that you bring the two together and compare them to see what's different?



i tested but not work ,
always in time unzip show message   :  "C:\Users\asghari\Downloads\MyZip.zip: Unexpected end of archive " and file in server directory is 60kB and after download is 56kB and if line below add to code

in time download show this alert :
                                                                                                                 

 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I was sort of hoping for something a bit more obvious...

One thing, though, can you give us the actual code for this line in your server code?
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Yeah, I was sort of hoping for something a bit more obvious...

One thing, though, can you give us the actual code for this line in your server code?



i reply in

abed asghari wrote:Ron McLeod i checked zip file in server direction is correct but after download is corrupt

 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abed asghari wrote:i tested but not work ,
always in time unzip show message   :  "C:\Users\asghari\Downloads\MyZip.zip: Unexpected end of archive " and file in server directory is 60kB and after download is 56kB...



Then I would change your servlet so that it writes the data to the response and also writes the same data to a file on the server. Then compare the two if there's still a problem.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


By the way, isn't closing the servlet's output stream a rather unusual thing to do? It's been a while since I wrote a servlet but I don't ever remember doing that.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have seen that sort of thing before, but not for a while.
It's not necessary (and neither is flushing).
All of that is handled by the normal servlet flow.

Unless something later on is attempting to put more stuff onto the output (which would result in an IllegalStateException I think) then closing the stream here should not have an adverse effect.
Of course, since it's not needed then it's probably worth taking it out.
After all, this servlet is not responsible for the stream, it is just using it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic