1 // Deflater.java - Compress a data stream.
3 /* Copyright (C) 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 package java.util.zip;
13 import gnu.gcj.RawData;
20 /* Written using on-line Java Platform 1.2 API Specification
22 * Believed complete and correct.
27 public static final int BEST_COMPRESSION = 9;
28 public static final int BEST_SPEED = 1;
29 public static final int DEFAULT_COMPRESSION = -1;
30 public static final int NO_COMPRESSION = 0;
32 public static final int DEFAULT_STRATEGY = 0;
33 public static final int FILTERED = 1;
34 public static final int HUFFMAN_ONLY = 2;
36 public static final int DEFLATED = 8;
38 public int deflate (byte[] buf)
40 return deflate (buf, 0, buf.length);
43 public native int deflate (byte[] buf, int off, int len);
44 public native void init (int level, boolean noHeader);
45 public native void update ();
49 this (DEFAULT_COMPRESSION, false);
52 public Deflater (int lvl)
57 public Deflater (int lvl, boolean noHeader)
59 this.strategy = DEFAULT_STRATEGY;
64 public native void end ();
66 public void finalize ()
71 public native void finish ();
73 public synchronized boolean finished ()
78 public native int getAdler ();
79 public native int getTotalIn ();
80 public native int getTotalOut ();
81 public native boolean needsInput ();
82 public native void reset ();
84 public void setDictionary (byte[] buf)
86 setDictionary (buf, 0, buf.length);
89 public native void setDictionary (byte[] buf, int off, int len);
91 public void setInput (byte[] buf)
93 setInput (buf, 0, buf.length);
96 public native void setInput (byte[] buf, int off, int len);
98 public synchronized void setLevel (int lvl)
100 if (lvl != -1 && (lvl < 0 || lvl > 9))
101 throw new IllegalArgumentException ();
102 level = (lvl == -1) ? 6 : lvl;
106 public synchronized void setStrategy (int stgy)
108 if (stgy != DEFAULT_STRATEGY && stgy != FILTERED
109 && stgy != HUFFMAN_ONLY)
110 throw new IllegalArgumentException ();
115 // Compression level.
118 // Compression strategy.
119 private int strategy;
122 private RawData zstream;
125 private boolean is_finished;
127 // `Flush' flag to pass to next call to deflate.
128 private int flush_flag;