File: test_stream_deflate_inflate.java

package info (click to toggle)
jzlib 1.1.3-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 608 kB
  • sloc: java: 5,293; xml: 35; makefile: 3
file content (25 lines) | stat: -rw-r--r-- 777 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* -*-mode:java; c-basic-offset:2; -*- */
import java.io.*;
import com.jcraft.jzlib.*;

public class test_stream_deflate_inflate{
  public static void main(String[] args){
    try{
      String hello = "Hello World!";

      ByteArrayOutputStream out = new ByteArrayOutputStream();
      ZOutputStream zOut = new ZOutputStream(out, JZlib.Z_BEST_COMPRESSION);
      ObjectOutputStream objOut = new ObjectOutputStream(zOut);
      objOut.writeObject(hello);
      zOut.close();

      ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
      ZInputStream zIn = new ZInputStream(in);
      ObjectInputStream objIn = new ObjectInputStream(zIn);
      System.out.println(objIn.readObject());
    }
    catch (Exception e){
      e.printStackTrace();
    }
  }
}