/* Autor:           Dipl.-Inf., Dipl.-Ing. (FH) Michael Wilhelm
   Firma:           HS Harz, FB AI
   Version:         1.1
   Ersterstellung:  23.03.2013
   Letzte Änderung: 23.03.2013
*/
import java.io.*;
import java.util.zip.*;

// Zip-Datei erstellen

public class Write_gz {


  private static void pause() {
    try {
      System.in.read();
    }
    catch (IOException e) {
    }
  }  // pause

  private static final int BLOCKSIZE = 8192;

  private static void test(String sFilename) {
    GZIPOutputStream gzos = null;
    FileInputStream  fis  = null;
    try
    {
      gzos = new GZIPOutputStream( new FileOutputStream( sFilename + ".gz" ) );
      fis  = new FileInputStream( sFilename );
      byte[] buffer = new byte[ BLOCKSIZE ];
      int laenge = fis.read(buffer, 0, BLOCKSIZE);
      while (laenge != -1 ) {
        gzos.write( buffer, 0, laenge );
        laenge = fis.read(buffer, 0, BLOCKSIZE);
      }
    }
    catch ( IOException e ) {
      System.err.println( "Fehler beim Komprimieren " + sFilename );
    }
    finally {
      if ( fis != null )
        try { 
           fis.close(); 
        } catch ( 
             IOException e ) { 
          e.printStackTrace(); 
       }
      if ( gzos != null )
        try { 
          gzos.close(); 
        } catch ( IOException e ) { 
             e.printStackTrace(); 
       }
    }
    System.out.println("Es wurde die Datei write_gz.java.gz erzeugt");
    System.out.println("Bitte Taste druecken");
  }


  public static void main(String argv[]) {
    test("Write_gz.java");
    pause();
  }  // main
}



