home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / TOC42.EXE / Compress.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-29  |  2.0 KB  |  102 lines

  1. import java.io.BufferedInputStream;
  2. import java.io.BufferedOutputStream;
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.EOFException;
  6. import java.io.FileInputStream;
  7. import java.io.FileOutputStream;
  8. import java.io.FilterInputStream;
  9. import java.io.FilterOutputStream;
  10. import java.io.IOException;
  11.  
  12. public class Compress {
  13.    private static final int empty = -1;
  14.    private BufferedInputStream input;
  15.    private BufferedOutputStream output;
  16.    private CompressTable String_T;
  17.    // $FF: renamed from: C int
  18.    private int field_0;
  19.    // $FF: renamed from: WC int
  20.    private int field_1;
  21.    // $FF: renamed from: W int
  22.    private int field_2;
  23.    private int Output_Code = -1;
  24.    private int iEnd;
  25.  
  26.    public void WriteCode(int var1) throws IOException {
  27.       if (this.Output_Code == -1) {
  28.          this.output.write(var1 >>> 4 & 255);
  29.          this.Output_Code = var1 & 15;
  30.       } else {
  31.          this.output.write(this.Output_Code << 4 & 4080 | var1 >>> 8 & 15);
  32.          this.output.write(var1 & 255);
  33.          this.Output_Code = -1;
  34.       }
  35.    }
  36.  
  37.    public Compress(BufferedInputStream var1, BufferedOutputStream var2) {
  38.       this.input = var1;
  39.       this.output = var2;
  40.       this.iEnd = 0;
  41.       this.String_T = new CompressTable();
  42.    }
  43.  
  44.    public static void main(String[] var0) {
  45.       Compress var5 = null;
  46.       if (var0.length == 0 || var0.length > 2) {
  47.          System.out.println("Usage: java Compress Source Dest");
  48.          System.exit(0);
  49.       }
  50.  
  51.       try {
  52.          DataInputStream var1 = new DataInputStream(new FileInputStream(var0[0]));
  53.          DataOutputStream var2 = new DataOutputStream(new FileOutputStream(var0[1]));
  54.          BufferedInputStream var3 = new BufferedInputStream(var1, 16384);
  55.          BufferedOutputStream var4 = new BufferedOutputStream(var2, 16384);
  56.          var5 = new Compress(var3, var4);
  57.          var5.ZLW();
  58.          ((FilterInputStream)var3).close();
  59.          ((FilterOutputStream)var4).close();
  60.          ((FilterInputStream)var1).close();
  61.          ((FilterOutputStream)var2).close();
  62.       } catch (IOException var6) {
  63.       }
  64.    }
  65.  
  66.    public void ZLW() throws IOException {
  67.       short var1 = 32767;
  68.       byte var2 = -1;
  69.  
  70.       try {
  71.          this.field_0 = this.input.read();
  72.          this.field_2 = this.String_T.Lookup_String(var1, this.field_0);
  73.          this.field_0 = this.input.read();
  74.  
  75.          try {
  76.             while(true) {
  77.                this.field_1 = this.String_T.Lookup_String(this.field_2, this.field_0);
  78.                if (this.field_1 == var2) {
  79.                   this.String_T.Make_Table_Element(this.field_2, this.field_0);
  80.                   this.WriteCode(this.field_2);
  81.                   this.field_2 = this.String_T.Lookup_String(var1, this.field_0);
  82.                } else {
  83.                   this.field_2 = this.field_1;
  84.                }
  85.  
  86.                if ((this.field_0 = this.input.read()) == -1) {
  87.                   if (++this.iEnd >= 4) {
  88.                      throw new EOFException();
  89.                   }
  90.  
  91.                   this.field_0 = 13;
  92.                }
  93.             }
  94.          } catch (EOFException var3) {
  95.             this.WriteCode(this.field_2);
  96.             this.output.flush();
  97.          }
  98.       } catch (IOException var4) {
  99.       }
  100.    }
  101. }
  102.