package com.tutego.insel.solutions.io;

import java.io.*;
import java.util.*;
import java.util.zip.*;

public class ObjektReader
{
  @SuppressWarnings("unchecked")
  public static void main( String args[] ) throws Exception
  {
    
    HashMap<String, Integer> hm = new HashMap<String, Integer>();
    hm.put( "Eins",new Integer(1) );
    hm.put( "Zwei",new Integer(2) );
    hm.put( "Drei",new Integer(3) );
    
    OutputStream fos = new FileOutputStream( "hash.ser" );
    OutputStream bos = new BufferedOutputStream( fos );
    OutputStream gzos =new GZIPOutputStream( bos );
    ObjectOutputStream oos = new ObjectOutputStream( gzos );
    
    oos.writeObject(hm);
    
    oos.close();
    
    //*************************************************
    
    InputStream fis = new FileInputStream( "hash.ser" );
    InputStream bis = new BufferedInputStream( fis );
    InputStream gzis = new GZIPInputStream( bis );
    ObjectInputStream ois = new ObjectInputStream( gzis );
    
    hm = (HashMap<String, Integer>) ois.readObject();
    
    ois.close();

    System.out.println( hm );
  }
}
