Solved

Compression of a seriaizable object

Posted on 2004-04-12
6
272 Views
Last Modified: 2011-04-14
I'm looking for a simple example of compressing a serializable object using the GZIPInputStream and GZIPOutputStream classes in java.util.zip package.  Any help will be greatly appreciated.
0
Comment
Question by:mwalker
[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
  • 3
  • 2
6 Comments
 
LVL 4

Accepted Solution

by:
brunomsilva earned 50 total points
ID: 10808968

to write:

FileOutputStream fos = new FileOutputStream(filename);
GZIPOutputStream gzos = new GZIPOutputStream(fos);    
ObjectOutputStream out = new ObjectOutputStream(gzos);
out.writeObject(new String("test string"));

to read:

FileInputStream fis = new FileInputStream(filename);
GZIPInputStream gzis = new GZIPInputStream(fis);
ObjectInputStream in = new ObjectInputStream(gzis);
String test = (Vector)in.readObject();  // this depends on what you want to write

don't forget to add the exception handling

cheers,
 bruno
0
 
LVL 14

Assisted Solution

by:Tommy Braas
Tommy Braas earned 25 total points
ID: 10808987
ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(myFile)));
oos.writeObject(mySerializableObject);

ObjectInputStream ois = new ObjectInputStream(new GZIPInputStream(new FileInputStream(myFile)));
Object deserialized = ois.readObject();
0
 
LVL 3

Assisted Solution

by:int_20h
int_20h earned 25 total points
ID: 10809002
// Serialize & Zip
{
  MyObject myobj = new MyObject();
  FileOutputStream fos = new FileOutputStream("data.dat");
  GZIPOutputStream gos = new GZIPOutputStream(fos);
  ObjectOutputStream oos = new ObjectOutputStream(gos);
  oos.writeObject(myobj);
}
// Unzip & De-serialize
{
  MyObject myobj = null;
  FileInputStream fis = new FileInputStream("data.dat");
  GZIPInputStream gis = new GZIPInputStream(fis);
  ObjectInputStream ois = new ObjectInputStream(gis);
  myobj = (MyObject) ois.readObject();  
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10809176
int_20h, please don't post already posted information
0
 
LVL 3

Expert Comment

by:int_20h
ID: 10809249
Sorry... I was writting the information when there was no answer.  After I answer I saw all other replies!
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10809405
That's ok. ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat administrtor 12 68
going to wrong jsp page 2 50
Java Eclipse Loop 3 31
jmeter usage 4 38
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

730 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