How to decompress serialized object from a Gzip file
Written on January 26, 2010 at 2:30 am by
mkyong
In last section, you learn about how to compress a serialized object into a file, now you learn how to decompress it from a Gzip file.
FileInputStream fin = new FileInputStream("c:\\address.gz"); GZIPInputStream gis = new GZIPInputStream(fin); ObjectInputStream ois = new ObjectInputStream(gis); address = (Address) ois.readObject();
GZIP example
In this example, you will decompress a compressed file “address.gz“, and print it out the value.
package com.mkyong.io; import java.io.FileInputStream; import java.io.ObjectInputStream; import java.io.Serializable; import java.util.zip.GZIPInputStream; public class Deserializer implements Serializable{ public static void main (String args[]) { Deserializer deserializer = new Deserializer(); Address address = deserializer.deserialzeAddress(); System.out.println(address); } public Address deserialzeAddress(){ Address address; try{ FileInputStream fin = new FileInputStream("c:\\address.gz"); GZIPInputStream gis = new GZIPInputStream(fin); ObjectInputStream ois = new ObjectInputStream(gis); address = (Address) ois.readObject(); ois.close(); return address; }catch(Exception ex){ ex.printStackTrace(); return null; } } }
Output
Street : wall street Country : united state
This article was posted in Java category.
Oracle Magazine - Free Magazine
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for Java's developers and DBAs, and more.
Securing & Optimizing Linux: The Hacking Solution - Free Guide
A comprehensive collection of Linux security products and explanations in the most simple and structured manner on how to safely and easily configure and run many popular Linux-based applications and services.
The Windows 7 Guide: From Newbies to Pros - Free Guide
In this 46 page guide you will be introduced to Windows 7 and what it has to offer. This guide will go over the software compatible issues, you will learn about the new taskbar, how to use and customize Windows Aero, what Windows 7 Libraries are all about, what software is included in Windows 7, and how easy networking is with Windows 7 along with other topics.
All Java Tutorials
- Java Core Technology - Java RegEx, Java XML, Java I/O, Java Misc
- J2EE Frameworks - Hibernate, Spring 2.5, Spring MVC, Struts 1.x, Struts 2.x
- Build Tools - Maven, Archiva
- Unit Test - jUnit, TestNG
- Client Scripts - jQuery