|
![]() |
trupti nigam wrote:I was able to solve the issue.
Now there is only one issue. When I unzip the file and try to open the xml file in text pad, I see some unwnated chars at the beginning of the file. Due to this The file won't open in Explorer.
How can I avoid those chars?
thanks
Trupti
Richard Tookey wrote:
trupti nigam wrote:I was able to solve the issue.
Doesn't sound like it to me! If you are still zipping the file twice or you are still setting the content length to a hard coded value then you have not fixed anything.
Now there is only one issue. When I unzip the file and try to open the xml file in text pad, I see some unwnated chars at the beginning of the file. Due to this The file won't open in Explorer.
How can I avoid those chars?
thanks
Trupti
I still think you have the same problem in a different guise BUT I don't have a view of your latest code.
trupti nigam wrote:
This is working finr and the end user does get the zip file.
Paul Clapham wrote:The originally-posted code takes a file named X and zips that into a zip archive. Then it sends that zip archive as the response, saying (via the Content-Distribution header) that its name is X.
This isn't consistent with X being named something.xml, because then the zip file arriving at the browser would be named something.xml instead of somethingelse.zip. However it is consistent with X being named something.zip, because then the zip file arriving at the browser would be named something.zip and everything would be normal.
So something is screwy here. Either you're zipping a zip file, as Richard suspects, or you're doing something else wrong. At any rate it would be extremely easy to look at this so-called unzipped XML file in a text editor and see if it's really that. Textpad isn't the only text editor in the world, or even on your computer.
Richard Tookey wrote:So what code generates the file opened by
P.S. You still don't set the content length. There is no need to close 'fis' since the close of 'bis' cascades to 'fis' . There is no need to allocate a buffer the size of the file; a fixed size of 16K odd will do. There is no need to buffer the zipped file in the ByteArrayOutputStream; you can write it directly to the ServletOutputStream.
Paul Clapham wrote:Actually the question to be answered is whether the unzipped version of the file is the same as the original file.
All you have said so far is that the unzipped version can't be loaded into Textpad when it's received. You haven't said that the original version can be loaded into Textpad. For all you know, the two files are identical and you are spending unnecessary time looking at your code.
trupti nigam wrote:Here is new code after your suggestions.
Richard Tookey wrote:
trupti nigam wrote:Here is new code after your suggestions.
Why on earth are you doing this???
I'm now betting that the bytes at the beggining of the file are the BOM (Byte Order Mark) probably introduced by Notepad or some other silly editor. You most definitely need to post the hex representation of the file.
Richard Tookey wrote:You just don't need those last three lines of code!! The zip content has been written already!
Who generated that XML and how? I'm betting it was generated using Notepad. If so then the first three bytes is a BOM and need to be removed before zipping. There is a class I wrote several year ago called BOMStripperiInputStream that can be obtained from http://code.google.com/p/train-graph/source/browse/trunk/src/org/paradise/etrc/data/BOMStripperInputStream.java?r=31 . If you use this to wrap the XML input stream before using it it will get rid of the BOM.
Richard Tookey wrote:You just don't need those last three lines of code!! The zip content has been written already!
Ok I removed the last 3 lines of the code and it still does not work. Some random download file gets created which is in currupt format.
trupti nigam wrote:
Richard Tookey wrote:You just don't need those last three lines of code!! The zip content has been written already!
Who generated that XML and how? I'm betting it was generated using Notepad. If so then the first three bytes is a BOM and need to be removed before zipping. There is a class I wrote several year ago called BOMStripperiInputStream that can be obtained from http://code.google.com/p/train-graph/source/browse/trunk/src/org/paradise/etrc/data/BOMStripperInputStream.java?r=31 . If you use this to wrap the XML input stream before using it it will get rid of the BOM.
In the earlier responses you asked me how am I generating the original file which I zip. Please see the code , how I am generating the original .xml file. This file when sent over servletOutput stream does not contain BOM. But when I zip it and send it to end user and the end user opens the file , I see BOM.
trupti nigam wrote:Here are the final things.
your suggestion of "You should just write the bytes of secResponse! Since I don't know what secResponse is I can't say more at the moment! " does not work.
The BomStripper code does not work.
I tried using it but I still see those chars.
Richard Tookey wrote:
trupti nigam wrote:Here are the final things.
your suggestion of "You should just write the bytes of secResponse! Since I don't know what secResponse is I can't say more at the moment! " does not work.
The BomStripper code does not work.
I tried using it but I still see those chars.
I have already said that the BOM stripper will not work since the problem is in your file generation and your use of ObjectOutputStream to write the fle!
I still think you don't actually need to write the file in the first place but without a bigger view of your code I can't be certain. Does your servlet write the file before reading it back in to be zipped?
trupti nigam wrote:Thanks for all the code. It worked with little modification in the above code.
with your code it was creating the file "download" with no extenstion. When I renamed the file to "download.zip" i was able to open it like regualr text file. But with above modification I am able to get the file with "xyz.zip" format and the inside file does not have BOM.
thanks a lot for your consistent help!
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|