3909N/A * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class provides support for general purpose decompression using the 0N/A * popular ZLIB compression library. The ZLIB compression library was 0N/A * initially developed as part of the PNG graphics standard and is not 0N/A * protected by patents. It is fully described in the specifications at 0N/A * package description</a>. 0N/A * <p>The following code fragment demonstrates a trivial compression 0N/A * and decompression of a string using <tt>Deflater</tt> and 0N/A * <tt>Inflater</tt>. 0N/A * // Encode a String into bytes 0N/A * String inputString = "blahblahblah\u20AC\u20AC"; 0N/A * byte[] input = inputString.getBytes("UTF-8"); 0N/A * // Compress the bytes 0N/A * byte[] output = new byte[100]; 0N/A * Deflater compresser = new Deflater(); 0N/A * compresser.setInput(input); 0N/A * compresser.finish(); 0N/A * int compressedDataLength = compresser.deflate(output); 0N/A * // Decompress the bytes 0N/A * Inflater decompresser = new Inflater(); 0N/A * decompresser.setInput(output, 0, compressedDataLength); 0N/A * byte[] result = new byte[100]; 0N/A * int resultLength = decompresser.inflate(result); 0N/A * decompresser.end(); 0N/A * // Decode the bytes into a String 0N/A * String outputString = new String(result, 0, resultLength, "UTF-8"); 0N/A * } catch(java.io.UnsupportedEncodingException ex) { 0N/A * } catch (java.util.zip.DataFormatException ex) { 0N/A * </pre></blockquote> 0N/A * @author David Connelly 0N/A * Creates a new decompressor. If the parameter 'nowrap' is true then 0N/A * the ZLIB header and checksum fields will not be used. This provides 0N/A * compatibility with the compression format used by both GZIP and PKZIP. 0N/A * Note: When using the 'nowrap' option it is also necessary to provide 0N/A * an extra "dummy" byte as input. This is required by the ZLIB native 0N/A * library in order to support certain optimizations. 0N/A * @param nowrap if true then support GZIP compatible compression 0N/A * Creates a new decompressor. 0N/A * Sets input data for decompression. Should be called whenever 0N/A * needsInput() returns true indicating that more input data is 0N/A * @param b the input data bytes 0N/A * @param off the start offset of the input data 0N/A * @param len the length of the input data 0N/A * @see Inflater#needsInput 0N/A * Sets input data for decompression. Should be called whenever 0N/A * needsInput() returns true indicating that more input data is 0N/A * @param b the input data bytes 0N/A * @see Inflater#needsInput 0N/A * Sets the preset dictionary to the given array of bytes. Should be 0N/A * called when inflate() returns 0 and needsDictionary() returns true 0N/A * indicating that a preset dictionary is required. The method getAdler() 0N/A * can be used to get the Adler-32 value of the dictionary needed. 0N/A * @param b the dictionary data bytes 0N/A * @param off the start offset of the data 0N/A * @param len the length of the data 0N/A * @see Inflater#needsDictionary 0N/A * @see Inflater#getAdler 0N/A * Sets the preset dictionary to the given array of bytes. Should be 0N/A * called when inflate() returns 0 and needsDictionary() returns true 0N/A * indicating that a preset dictionary is required. The method getAdler() 0N/A * can be used to get the Adler-32 value of the dictionary needed. 0N/A * @param b the dictionary data bytes 0N/A * @see Inflater#needsDictionary 0N/A * @see Inflater#getAdler 0N/A * Returns the total number of bytes remaining in the input buffer. 0N/A * This can be used to find out what bytes still remain in the input 0N/A * buffer after decompression has finished. 0N/A * @return the total number of bytes remaining in the input buffer 0N/A * Returns true if no data remains in the input buffer. This can 0N/A * be used to determine if #setInput should be called in order 0N/A * to provide more input. 0N/A * @return true if no data remains in the input buffer 0N/A * Returns true if a preset dictionary is needed for decompression. 0N/A * @return true if a preset dictionary is needed for decompression 0N/A * @see Inflater#setDictionary 0N/A * Returns true if the end of the compressed data stream has been 0N/A * @return true if the end of the compressed data stream has been 0N/A * Uncompresses bytes into specified buffer. Returns actual number 0N/A * of bytes uncompressed. A return value of 0 indicates that 0N/A * needsInput() or needsDictionary() should be called in order to 0N/A * determine if more input data or a preset dictionary is required. 0N/A * In the latter case, getAdler() can be used to get the Adler-32 0N/A * value of the dictionary required. 0N/A * @param b the buffer for the uncompressed data 0N/A * @param off the start offset of the data 0N/A * @param len the maximum number of uncompressed bytes 0N/A * @return the actual number of uncompressed bytes 0N/A * @exception DataFormatException if the compressed data format is invalid 0N/A * @see Inflater#needsInput 0N/A * @see Inflater#needsDictionary 0N/A * Uncompresses bytes into specified buffer. Returns actual number 0N/A * of bytes uncompressed. A return value of 0 indicates that 0N/A * needsInput() or needsDictionary() should be called in order to 0N/A * determine if more input data or a preset dictionary is required. 0N/A * In the latter case, getAdler() can be used to get the Adler-32 0N/A * value of the dictionary required. 0N/A * @param b the buffer for the uncompressed data 0N/A * @return the actual number of uncompressed bytes 0N/A * @exception DataFormatException if the compressed data format is invalid 0N/A * @see Inflater#needsInput 0N/A * @see Inflater#needsDictionary 0N/A * Returns the ADLER-32 value of the uncompressed data. 0N/A * @return the ADLER-32 value of the uncompressed data 0N/A * Returns the total number of compressed bytes input so far. 0N/A * <p>Since the number of bytes may be greater than 0N/A * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now 0N/A * the preferred means of obtaining this information.</p> 0N/A * @return the total number of compressed bytes input so far 0N/A * Returns the total number of compressed bytes input so far.</p> 0N/A * @return the total (non-negative) number of compressed bytes input so far 0N/A * Returns the total number of uncompressed bytes output so far. 0N/A * <p>Since the number of bytes may be greater than 0N/A * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now 0N/A * the preferred means of obtaining this information.</p> 0N/A * @return the total number of uncompressed bytes output so far 0N/A * Returns the total number of uncompressed bytes output so far.</p> 0N/A * @return the total (non-negative) number of uncompressed bytes output so far 0N/A * Resets inflater so that a new set of input data can be processed. 0N/A * Closes the decompressor and discards any unprocessed input. 0N/A * This method should be called when the decompressor is no longer 0N/A * being used, but will also be called automatically by the finalize() 0N/A * method. Once this method is called, the behavior of the Inflater 0N/A * object is undefined. 0N/A * Closes the decompressor when garbage is collected.