OSDN Git Service

* java/util/zip/ZipInputStream.java (fill): New method.
[pf3gnuchains/gcc-fork.git] / libjava / java / util / zip / Deflater.java
1 // Deflater.java - Compress a data stream.
2
3 /* Copyright (C) 1999  Cygnus Solutions
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 package java.util.zip;
12
13 import gnu.gcj.RawData;
14
15 /**
16  * @author Tom Tromey
17  * @date May 17, 1999
18  */
19
20 /* Written using on-line Java Platform 1.2 API Specification
21  * and JCL book.
22  * Believed complete and correct.
23  */
24
25 public class Deflater
26 {
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;
31
32   public static final int DEFAULT_STRATEGY = 0;
33   public static final int FILTERED = 1;
34   public static final int HUFFMAN_ONLY = 2;
35
36   public static final int DEFLATED = 8;
37
38   public int deflate (byte[] buf)
39   {
40     return deflate (buf, 0, buf.length);
41   }
42
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 ();
46
47   public Deflater ()
48   {
49     this (DEFAULT_COMPRESSION, false);
50   }
51
52   public Deflater (int lvl)
53   {
54     this (lvl, false);
55   }
56
57   public Deflater (int lvl, boolean noHeader)
58   {
59     this.strategy = DEFAULT_STRATEGY;
60     init (lvl, noHeader);
61     setLevel (lvl);
62   }
63
64   public native void end ();
65
66   public void finalize ()
67   {
68     end ();
69   }
70
71   public native void finish ();
72
73   public synchronized boolean finished ()
74   {
75     return is_finished;
76   }
77
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 ();
83
84   public void setDictionary (byte[] buf)
85   {
86     setDictionary (buf, 0, buf.length);
87   }
88
89   public native void setDictionary (byte[] buf, int off, int len);
90
91   public void setInput (byte[] buf)
92   {
93     setInput (buf, 0, buf.length);
94   }
95
96   public native void setInput (byte[] buf, int off, int len);
97
98   public synchronized void setLevel (int lvl)
99   {
100     if (lvl != -1 && (lvl < 0 || lvl > 9))
101       throw new IllegalArgumentException ();
102     level = (lvl == -1) ? 6 : lvl;
103     update ();
104   }
105
106   public synchronized void setStrategy (int stgy)
107   {
108     if (stgy != DEFAULT_STRATEGY && stgy != FILTERED
109         && stgy != HUFFMAN_ONLY)
110       throw new IllegalArgumentException ();
111     strategy = stgy;
112     update ();
113   }
114
115   // Compression level.
116   private int level;
117
118   // Compression strategy.
119   private int strategy;
120
121   // The zlib stream.
122   private RawData zstream;
123
124   // True if finished.
125   private boolean is_finished;
126
127   // `Flush' flag to pass to next call to deflate.
128   private int flush_flag;
129 }