• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

using gzip to compress results

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi do you know of an example or tutorial

thanks
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic