?
Solved

GZIPInputStream reading

Posted on 2003-03-02
3
Medium Priority
?
203 Views
Last Modified: 2008-02-01
JDK's docs are horrible for those classes!

So, GZIPing is straightforward. But unzipping?

ByteArrayOutputStream bos = new ByteArrayOutputStream();
               GZIPOutputStream gos = new GZIPOutputStream(bos);
               ObjectOutputStream oos = new ObjectOutputStream(gos);
               oos.writeObject(data);
               System.out.println("zipped size = "+bos.size());
               
               ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
               System.out.println("available size = "+bis.available());
               GZIPInputStream gis = new GZIPInputStream(bis);
               
               ObjectInputStream ois = new ObjectInputStream(gis);

This obviously won't work. So how am I gonna get the decompressed data to the ObjectInputStream to get my object back?
0
Comment
Question by:piou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 8055133
Try calling finish() on your GZipOutputStream():

ByteArrayOutputStream bos = new ByteArrayOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(bos);
ObjectOutputStream oos = new ObjectOutputStream(gos);
oos.writeObject(data);
gos.finish();
System.out.println("zipped size = "+bos.size());
             
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
System.out.println("available size = "+bis.available());
GZIPInputStream gis = new GZIPInputStream(bis);
ObjectInputStream ois = new ObjectInputStream(gis);
Object x = ois.readObject();


0
 

Author Comment

by:piou
ID: 8055230
Cheers again! :)
0
 
LVL 92

Expert Comment

by:objects
ID: 8055468
No worries :-)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question