Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Compression of a seriaizable object

Posted on 2004-04-12
6
Medium Priority
?
281 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 150 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 75 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 75 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

Industry Leaders: 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!

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

636 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