Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / java / util / zip / Inflater.java
blobc51cde8022677b96bccfd12c075ec8a875b167fd
1 /* Inflater.java - Decompress a data stream
2 Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.util.zip;
40 import gnu.gcj.RawData;
42 /* Written using on-line Java Platform 1.2 API Specification
43 * and JCL book.
44 * Believed complete and correct.
47 /**
48 * Inflater is used to decompress data that has been compressed according
49 * to the "deflate" standard described in rfc1950.
51 * The usage is as following. First you have to set some input with
52 * <code>setInput()</code>, then inflate() it. If inflate doesn't
53 * inflate any bytes there may be three reasons:
54 * <ul>
55 * <li>needsInput() returns true because the input buffer is empty.
56 * You have to provide more input with <code>setInput()</code>.
57 * NOTE: needsInput() also returns true when, the stream is finished.
58 * </li>
59 * <li>needsDictionary() returns true, you have to provide a preset
60 * dictionary with <code>setDictionary()</code>.</li>
61 * <li>finished() returns true, the inflater has finished.</li>
62 * </ul>
63 * Once the first output byte is produced, a dictionary will not be
64 * needed at a later stage.
66 * @author John Leuner, Jochen Hoenicke
67 * @author Tom Tromey
68 * @date May 17, 1999
69 * @since JDK 1.1
71 public class Inflater
73 // The zlib stream.
74 private RawData zstream;
76 // True if finished.
77 private boolean is_finished;
79 // True if dictionary needed.
80 private boolean dict_needed;
82 /**
83 * Creates a new inflater.
85 public Inflater ()
87 this (false);
90 /**
91 * Creates a new inflater.
92 * @param nowrap true if no header and checksum field appears in the
93 * stream. This is used for GZIPed input. For compatibility with
94 * Sun JDK you should provide one byte of input more than needed in
95 * this case.
97 public Inflater (boolean noHeader)
99 init (noHeader);
103 * Finalizes this object.
105 protected void finalize ()
107 end ();
111 * Frees all objects allocated by the inflater. There's no reason
112 * to call this, since you can just rely on garbage collection (even
113 * for the Sun implementation). Exists only for compatibility
114 * with Sun's JDK, where the compressor allocates native memory.
115 * If you call any method (even reset) afterwards the behaviour is
116 * <i>undefined</i>.
117 * @deprecated Just clear all references to inflater instead.
119 public native void end ();
122 * Returns true, if the inflater has finished. This means, that no
123 * input is needed and no output can be produced.
125 public synchronized boolean finished ()
127 return is_finished;
131 * Gets the adler checksum. This is either the checksum of all
132 * uncompressed bytes returned by inflate(), or if needsDictionary()
133 * returns true (and thus no output was yet produced) this is the
134 * adler checksum of the expected dictionary.
135 * @returns the adler checksum.
137 public native int getAdler ();
140 * Gets the number of unprocessed input. Useful, if the end of the
141 * stream is reached and you want to further process the bytes after
142 * the deflate stream.
143 * @return the number of bytes of the input which were not processed.
145 public native int getRemaining ();
148 * Gets the total number of processed compressed input bytes.
149 * @return the total number of bytes of processed input bytes.
151 public native int getTotalIn ();
154 * Gets the total number of output bytes returned by inflate().
155 * @return the total number of output bytes.
157 public native int getTotalOut ();
160 * Inflates the compressed stream to the output buffer. If this
161 * returns 0, you should check, whether needsDictionary(),
162 * needsInput() or finished() returns true, to determine why no
163 * further output is produced.
164 * @param buffer the output buffer.
165 * @return the number of bytes written to the buffer, 0 if no further
166 * output can be produced.
167 * @exception DataFormatException if deflated stream is invalid.
168 * @exception IllegalArgumentException if buf has length 0.
170 public int inflate (byte[] buf) throws DataFormatException
172 return inflate (buf, 0, buf.length);
176 * Inflates the compressed stream to the output buffer. If this
177 * returns 0, you should check, whether needsDictionary(),
178 * needsInput() or finished() returns true, to determine why no
179 * further output is produced.
180 * @param buffer the output buffer.
181 * @param off the offset into buffer where the output should start.
182 * @param len the maximum length of the output.
183 * @return the number of bytes written to the buffer, 0 if no further
184 * output can be produced.
185 * @exception DataFormatException if deflated stream is invalid.
186 * @exception IndexOutOfBoundsException if the off and/or len are wrong.
188 public native int inflate (byte[] buf, int off, int len)
189 throws DataFormatException;
191 private native void init (boolean noHeader);
194 * Returns true, if a preset dictionary is needed to inflate the input.
196 public synchronized boolean needsDictionary ()
198 return dict_needed;
202 * Returns true, if the input buffer is empty.
203 * You should then call setInput(). <br>
205 * <em>NOTE</em>: This method also returns true when the stream is finished.
207 public synchronized boolean needsInput ()
209 return getRemaining () == 0;
213 * Resets the inflater so that a new stream can be decompressed. All
214 * pending input and output will be discarded.
216 public native void reset ();
219 * Sets the preset dictionary. This should only be called, if
220 * needsDictionary() returns true and it should set the same
221 * dictionary, that was used for deflating. The getAdler()
222 * function returns the checksum of the dictionary needed.
223 * @param buffer the dictionary.
224 * @exception IllegalStateException if no dictionary is needed.
225 * @exception IllegalArgumentException if the dictionary checksum is
226 * wrong.
228 public void setDictionary (byte[] buf)
230 setDictionary (buf, 0, buf.length);
234 * Sets the preset dictionary. This should only be called, if
235 * needsDictionary() returns true and it should set the same
236 * dictionary, that was used for deflating. The getAdler()
237 * function returns the checksum of the dictionary needed.
238 * @param buffer the dictionary.
239 * @param off the offset into buffer where the dictionary starts.
240 * @param len the length of the dictionary.
241 * @exception IllegalStateException if no dictionary is needed.
242 * @exception IllegalArgumentException if the dictionary checksum is
243 * wrong.
244 * @exception IndexOutOfBoundsException if the off and/or len are wrong.
246 public native void setDictionary (byte[] buf, int off, int len);
249 * Sets the input. This should only be called, if needsInput()
250 * returns true.
251 * @param buffer the input.
252 * @exception IllegalStateException if no input is needed.
254 public void setInput (byte[] buf)
256 setInput (buf, 0, buf.length);
260 * Sets the input. This should only be called, if needsInput()
261 * returns true.
262 * @param buffer the input.
263 * @param off the offset into buffer where the input starts.
264 * @param len the length of the input.
265 * @exception IllegalStateException if no input is needed.
266 * @exception IndexOutOfBoundsException if the off and/or len are wrong.
268 public native void setInput (byte[] buf, int off, int len);