This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Size of Compressed Data? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Size of Compressed Data?" Watch "Size of Compressed Data?" New topic

Size of Compressed Data?

ram ragu
Ranch Hand

Joined: Mar 12, 2002
Posts: 57
posted October 03, 2002 01:16 PM
I compress data using GZIPOutputStream. Is there any way to find out the size of the compressed data?
here is what I do
sb ( StringBuffer )has some data...

GZIPOutputStream gzos =
new GZIPOutputStream(response.getOutputStream());
Kindly let me know.. I need to find out how good the compression is..
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

Write it to a file and look at the file size?

Please ignore post, I have no idea what I am talking about.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

Create a ByteArrayOutputStream, "Baos".
Use "Baos" in the ctor of the GZIPOutputStream, "gzip".
Use the .write() method of the "gzip" object.
When done writing to gzip object say "Baos.size()". That is the size of your compressed data.
wood burning stoves
subject: Size of Compressed Data?
Similar Threads
data loss during file transfer from applet2servlet
Copying zip files
GZIPOutputStream - size of compressed data
Zipping an inputstream