KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test_stream_deflate_inflate


1 /* -*-mode:java; c-basic-offset:2; -*- */
2 import java.io.*;
3 import com.jcraft.jzlib.*;
4
5 public class test_stream_deflate_inflate{
6   public static void main(String JavaDoc[] args){
7     try{
8       ByteArrayOutputStream out=new ByteArrayOutputStream();
9       ZOutputStream zOut=new ZOutputStream(out, JZlib.Z_BEST_COMPRESSION);
10       ObjectOutputStream objOut=new ObjectOutputStream(zOut);
11       String JavaDoc hello="Hello World!";
12       objOut.writeObject(hello);
13       zOut.close();
14
15       ByteArrayInputStream in=new ByteArrayInputStream(out.toByteArray());
16       ZInputStream zIn=new ZInputStream(in);
17       ObjectInputStream objIn=new ObjectInputStream(zIn);
18       System.out.println(objIn.readObject());
19     }
20     catch (Exception JavaDoc e){
21       e.printStackTrace();
22     }
23   }
24 }
25
Popular Tags