Forums Register Login

using gzip to compress results

+Pie Number of slices to send: Send
hi all ,
i'm new to input/output streams and i'm very stuck

I'm using jdom to return a db recordset and format it as xml, like this

.......
RecordsetToXML rsXML = new RecordsetToXML(rs, "root", "record");
// create the XML from recordset
Document jDOMDoc = rsXML.build();
XMLOutputter outputter = new XMLOutputter();
outputter.output(jDOMDoc, writer);
result = writer.toString();
........
where result is the recordset from a db query formatted as xml

i now want to use gzip to compress the 'result'. I have this (http://javaalmanac.com/egs/java.util.zip/CompressFile.html) link but i'm confused how i pass the 'result' to the gzip method.

can anyone help me please

thanks for any help
+Pie Number of slices to send: Send
Create a ByteArrayOutputStream and wrap it into a

GZIPOutpuStream

Then stick this into a PrintStream or PrintWriter and write the string you want to compress into it. Close all streams and fetch the bytes from the ByteArrayOutputStream.
+Pie Number of slices to send: Send
hi do you know of an example or tutorial

thanks
+Pie Number of slices to send: Send
I did a search for "gzipinputstream" on java.sun.com and the first hit is an article: Compressing and Decompressing Data using Java.
You should probably look at the Java Tutorial chapter on IO first if you are unfamiliar with Java streams.
Get me the mayor's office! I need to tell him about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1070 times.
Similar Threads
Question: How do you send a JSP page as compressed GZIP encoding?
GZIP file append writing
Using gzip in jsp files
JSP page with js file compression
Log On help
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:46:22.