Java util zip inflater inflate

Java util zip inflater inflate

This class provides support for general purpose decompression using the popular ZLIB compression library. The ZLIB compression library was initially developed as part of the PNG graphics standard and is not protected by patents. It is fully described in the specifications at the java.util.zip package description. The following code fragment demonstrates a trivial compression and decompression of a string using Deflater and Inflater .

try < // Encode a String into bytes String inputString = "blahblahblah??"; byte[] input = inputString.getBytes("UTF-8"); // Compress the bytes byte[] output = new byte[100]; Deflater compresser = new Deflater(); compresser.setInput(input); compresser.finish(); int compressedDataLength = compresser.deflate(output); // Decompress the bytes Inflater decompresser = new Inflater(); decompresser.setInput(output, 0, compressedDataLength); byte[] result = new byte[100]; int resultLength = decompresser.inflate(result); decompresser.end(); // Decode the bytes into a String String outputString = new String(result, 0, resultLength, "UTF-8"); >catch(java.io.UnsupportedEncodingException ex) < // handle >catch (java.util.zip.DataFormatException ex) < // handle >

Constructor Summary

Method Summary

The finalize method has been deprecated. Subclasses that override finalize in order to perform cleanup should be modified to use alternative cleanup mechanisms and to remove the overriding finalize method. When overriding the finalize method, its implementation must explicitly ensure that super.finalize() is invoked as described in Object.finalize() . See the specification for Object.finalize() for further information about migration options.

Methods inherited from class java.lang.Object

Constructor Detail

Inflater

public Inflater​(boolean nowrap)

Creates a new decompressor. If the parameter ‘nowrap’ is true then the ZLIB header and checksum fields will not be used. This provides compatibility with the compression format used by both GZIP and PKZIP. Note: When using the ‘nowrap’ option it is also necessary to provide an extra «dummy» byte as input. This is required by the ZLIB native library in order to support certain optimizations.

Inflater

Method Detail

setInput

public void setInput​(byte[] b, int off, int len)

Sets input data for decompression. Should be called whenever needsInput() returns true indicating that more input data is required.

setInput

public void setInput​(byte[] b)

Sets input data for decompression. Should be called whenever needsInput() returns true indicating that more input data is required.

setDictionary

public void setDictionary​(byte[] b, int off, int len)

Sets the preset dictionary to the given array of bytes. Should be called when inflate() returns 0 and needsDictionary() returns true indicating that a preset dictionary is required. The method getAdler() can be used to get the Adler-32 value of the dictionary needed.

Читайте также:  Cause exception while getting updates python

setDictionary

public void setDictionary​(byte[] b)

Sets the preset dictionary to the given array of bytes. Should be called when inflate() returns 0 and needsDictionary() returns true indicating that a preset dictionary is required. The method getAdler() can be used to get the Adler-32 value of the dictionary needed.

getRemaining

Returns the total number of bytes remaining in the input buffer. This can be used to find out what bytes still remain in the input buffer after decompression has finished.

needsInput

public boolean needsInput​()

Returns true if no data remains in the input buffer. This can be used to determine if #setInput should be called in order to provide more input.

needsDictionary

public boolean needsDictionary​()

finished

inflate

Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed. A return value of 0 indicates that needsInput() or needsDictionary() should be called in order to determine if more input data or a preset dictionary is required. In the latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.

inflate

Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed. A return value of 0 indicates that needsInput() or needsDictionary() should be called in order to determine if more input data or a preset dictionary is required. In the latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.

getAdler

getTotalIn

Returns the total number of compressed bytes input so far. Since the number of bytes may be greater than Integer.MAX_VALUE, the getBytesRead() method is now the preferred means of obtaining this information.

getBytesRead

getTotalOut

Returns the total number of uncompressed bytes output so far. Since the number of bytes may be greater than Integer.MAX_VALUE, the getBytesWritten() method is now the preferred means of obtaining this information.

getBytesWritten

public long getBytesWritten​()

reset

end

Closes the decompressor and discards any unprocessed input. This method should be called when the decompressor is no longer being used, but will also be called automatically by the finalize() method. Once this method is called, the behavior of the Inflater object is undefined.

finalize

@Deprecated(since="9") protected void finalize​()

Deprecated. The finalize method has been deprecated. Subclasses that override finalize in order to perform cleanup should be modified to use alternative cleanup mechanisms and to remove the overriding finalize method. When overriding the finalize method, its implementation must explicitly ensure that super.finalize() is invoked as described in Object.finalize() . See the specification for Object.finalize() for further information about migration options.

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2017, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Читайте также:  Python tuple with one string

Источник

Java util zip inflater inflate

This class provides support for general purpose decompression using the popular ZLIB compression library. The ZLIB compression library was initially developed as part of the PNG graphics standard and is not protected by patents. It is fully described in the specifications at the java.util.zip package description. The following code fragment demonstrates a trivial compression and decompression of a string using Deflater and Inflater.

try < // Encode a String into bytes String inputString = "blahblahblah??"; byte[] input = inputString.getBytes("UTF-8"); // Compress the bytes byte[] output = new byte[100]; Deflater compresser = new Deflater(); compresser.setInput(input); compresser.finish(); int compressedDataLength = compresser.deflate(output); // Decompress the bytes Inflater decompresser = new Inflater(); decompresser.setInput(output, 0, compressedDataLength); byte[] result = new byte[100]; int resultLength = decompresser.inflate(result); decompresser.end(); // Decode the bytes into a String String outputString = new String(result, 0, resultLength, "UTF-8"); >catch(java.io.UnsupportedEncodingException ex) < // handle >catch (java.util.zip.DataFormatException ex) < // handle >

Constructor Summary

Method Summary

Methods inherited from class java.lang.Object

Constructor Detail

Inflater

public Inflater(boolean nowrap)

Creates a new decompressor. If the parameter ‘nowrap’ is true then the ZLIB header and checksum fields will not be used. This provides compatibility with the compression format used by both GZIP and PKZIP. Note: When using the ‘nowrap’ option it is also necessary to provide an extra «dummy» byte as input. This is required by the ZLIB native library in order to support certain optimizations.

Inflater

Method Detail

setInput

public void setInput(byte[] b, int off, int len)

Sets input data for decompression. Should be called whenever needsInput() returns true indicating that more input data is required.

setInput

public void setInput(byte[] b)

Sets input data for decompression. Should be called whenever needsInput() returns true indicating that more input data is required.

setDictionary

public void setDictionary(byte[] b, int off, int len)

Sets the preset dictionary to the given array of bytes. Should be called when inflate() returns 0 and needsDictionary() returns true indicating that a preset dictionary is required. The method getAdler() can be used to get the Adler-32 value of the dictionary needed.

setDictionary

public void setDictionary(byte[] b)

Sets the preset dictionary to the given array of bytes. Should be called when inflate() returns 0 and needsDictionary() returns true indicating that a preset dictionary is required. The method getAdler() can be used to get the Adler-32 value of the dictionary needed.

getRemaining

Returns the total number of bytes remaining in the input buffer. This can be used to find out what bytes still remain in the input buffer after decompression has finished.

needsInput

public boolean needsInput()

Returns true if no data remains in the input buffer. This can be used to determine if #setInput should be called in order to provide more input.

needsDictionary

public boolean needsDictionary()

finished

inflate

Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed. A return value of 0 indicates that needsInput() or needsDictionary() should be called in order to determine if more input data or a preset dictionary is required. In the latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.

Читайте также:  What is there in advanced java

inflate

Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed. A return value of 0 indicates that needsInput() or needsDictionary() should be called in order to determine if more input data or a preset dictionary is required. In the latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.

getAdler

getTotalIn

Returns the total number of compressed bytes input so far. Since the number of bytes may be greater than Integer.MAX_VALUE, the getBytesRead() method is now the preferred means of obtaining this information.

getBytesRead

getTotalOut

Returns the total number of uncompressed bytes output so far. Since the number of bytes may be greater than Integer.MAX_VALUE, the getBytesWritten() method is now the preferred means of obtaining this information.

getBytesWritten

public long getBytesWritten()

reset

end

Closes the decompressor and discards any unprocessed input. This method should be called when the decompressor is no longer being used, but will also be called automatically by the finalize() method. Once this method is called, the behavior of the Inflater object is undefined.

finalize

Источник

Inflater. Inflate Method

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

Uncompresses bytes into specified buffer.

Uncompresses bytes into specified buffer.

Inflate(Byte[])

Uncompresses bytes into specified buffer.

[Android.Runtime.Register("inflate", "([B)I", "GetInflate_arrayBHandler")] public virtual int Inflate (byte[]? b);
[] abstract member Inflate : byte[] -> int override this.Inflate : byte[] -> int

Parameters

the buffer for the uncompressed data

Returns

the actual number of uncompressed bytes

Exceptions

if the underlying stream is corrupted or was not compressed using a Deflater .

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Inflate(Byte[], Int32, Int32)

Uncompresses bytes into specified buffer.

[Android.Runtime.Register("inflate", "([BII)I", "GetInflate_arrayBIIHandler")] public virtual int Inflate (byte[]? b, int off, int len);
[] abstract member Inflate : byte[] * int * int -> int override this.Inflate : byte[] * int * int -> int

Parameters

the buffer for the uncompressed data

the start offset of the data

the maximum number of uncompressed bytes

Returns

the actual number of uncompressed bytes

Exceptions

if the underlying stream is corrupted or was not compressed using a Deflater .

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Источник

Оцените статью