• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

GZIPInputStream reading

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
piou
Asked:
piou
  • 2
1 Solution
 
objectsCommented:
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
 
piouAuthor Commented:
Cheers again! :)
0
 
objectsCommented:
No worries :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now