• Post Reply Bookmark Topic Watch Topic
  • New Topic

using gzip to compress results  RSS feed

 
dale con
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Harald Kirsch
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
dale con
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi do you know of an example or tutorial

thanks
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!