Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to stream out a gzipped xml file

843834Nov 22 2005
I am trying to stream out an xml file which I have in gzip format through a socket. I want to be able to display the xml file in a web browser.

This is what I've tried:
1 - I've written the MIME header: "text/xml content-encoding: gzip" to the outputstream
2 - I've open and read the file and then written it out to the outputstream.

... this is a sample code

OutputStream out; // this is already pointing to my output stream.

File myFile = new File(fileName);
FileInputStream inputFile = new FileInputStream(myFile);
byte[] buffer = new byte[1024];
int bytes = 0;

while (bytes != -1) {
bytes = inputFile.read(buffer);
out.write(buffer,0,bytes);
}
out.flush();


This is my problem:
I get the following error in the browser:
=====================================================
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
An invalid character was found in text content. Error processing resource 'http://xx.xx.xx.xx/cgi-bin/CGILink?cmd=vfuellog...
======================================================

I think the problem is somehow related to the fact that I am writing an uncompressed string to the outputstream (the MIME header) and then I am sending the compressed information (note: I also tried wrapping my outputstream with a GZIPOutputStream but did not work ... and does not make sense to me to do that anyway - got the exact same error in the browser when I did that).

Can anybody point me in the right direction on how to add the MIME header for a gzip file, and then stream out the gzip file? ... note, I don't want to create a file, but just stream it out. However, for debugging purposes I wrote to a FileOutputStream instead and the created file was perfectly OK (I opened it both with winzip and gzcat).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 20 2005
Added on Nov 22 2005
0 comments
224 views