IP*Works! ZIP V8

ipworkszip
Class Zipstream

java.lang.Object
  |
  +--ipworkszip.Zipstream

public class Zipstream
extends java.lang.Object

The ZipStream bean is used to perform compression or decompression on streams.

The ZipStream bean operates by producing streams that read or write compressed data, as appropriate. The GetDecompressionStream and GetCompressionStream methods are used to retrieve streams that read or write compressed data, as appropriate; the underlying stream should be passed to either method as a parameter.

The bean may be used to read and write the zlib format, as specified in RFC 1950, deflate , as specified in RFC 1951, or gzip , as specified in RFC 1952.

For additional ease of use, the CompressData and DecompressData methods are also provided to compress or decompress byte arrays with a single line of code.


Field Summary
static int sfDeflate
           
static int sfGzip
           
static int sfZlib
           
 
Constructor Summary
Zipstream()
           
 
Method Summary
 void addZipstreamEventListener(ipworkszip.ZipstreamEventListener l)
           
 byte[] compressData(byte[] data)
          Compresses a byte array.
 java.lang.String config(java.lang.String configurationString)
          Sets or retrieves a configuration setting.
 byte[] decompressData(byte[] data)
          Decompresses a byte array.
 int getCompressionLevel()
          The compression level to use.
 java.io.OutputStream getCompressionStream(java.io.OutputStream baseStream)
          Creates an output stream used to write compressed data.
 java.io.InputStream getDecompressionStream(java.io.InputStream baseStream)
          Creates an input stream used to read data from a compressed stream.
 int getStreamFormat()
          The stream format to use.
 boolean isCloseBaseStream()
          Whether or not to close the underlying stream.
 void removeZipstreamEventListener(ipworkszip.ZipstreamEventListener l)
           
 void setCloseBaseStream(boolean closeBaseStream)
          Whether or not to close the underlying stream.
 void setCompressionLevel(int compressionLevel)
          The compression level to use.
 void setStreamFormat(int streamFormat)
          The stream format to use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sfDeflate

public static final int sfDeflate
See Also:
Constant Field Values

sfZlib

public static final int sfZlib
See Also:
Constant Field Values

sfGzip

public static final int sfGzip
See Also:
Constant Field Values
Constructor Detail

Zipstream

public Zipstream()
Method Detail

isCloseBaseStream

public boolean isCloseBaseStream()
Whether or not to close the underlying stream.

If true, streams created by GetCompressionStream and GetDecompressionStream will close their underlying streams when their Close method is invoked. If false, the underlying streams will remain open.


setCloseBaseStream

public void setCloseBaseStream(boolean closeBaseStream)
                        throws IPWorksZipException
Whether or not to close the underlying stream.

If true, streams created by GetCompressionStream and GetDecompressionStream will close their underlying streams when their Close method is invoked. If false, the underlying streams will remain open.

IPWorksZipException

getCompressionLevel

public int getCompressionLevel()
The compression level to use.

The compression level to use, from 1 to 6. Higher values will cause the component to compress better; lower values will cause the component to compress faster.

When GetCompressionStream is invoked the stream will be created with the specified compression level. After a stream has been created it is independent of the control, and changing CompressionLevel will have no effect on existing streams.


setCompressionLevel

public void setCompressionLevel(int compressionLevel)
                         throws IPWorksZipException
The compression level to use.

The compression level to use, from 1 to 6. Higher values will cause the component to compress better; lower values will cause the component to compress faster.

When GetCompressionStream is invoked the stream will be created with the specified compression level. After a stream has been created it is independent of the control, and changing CompressionLevel will have no effect on existing streams.

IPWorksZipException

getStreamFormat

public int getStreamFormat()
The stream format to use.

The stream format to use, by default Deflate .

All three stream formats use the Deflate algorithm specified in RFC 1951, which is the same algorithm used by Zip . The Zlib stream format adds a two-byte header and an Adler-32 checksum; the Gzip format adds a longer header and a CRC checksum, and is identical to the Gzip file format.

Caution : The terms zlib and deflate are sometimes used interchangeably (which is technically incorrect).


setStreamFormat

public void setStreamFormat(int streamFormat)
                     throws IPWorksZipException
The stream format to use.

The stream format to use, by default Deflate .

All three stream formats use the Deflate algorithm specified in RFC 1951, which is the same algorithm used by Zip . The Zlib stream format adds a two-byte header and an Adler-32 checksum; the Gzip format adds a longer header and a CRC checksum, and is identical to the Gzip file format.

Caution : The terms zlib and deflate are sometimes used interchangeably (which is technically incorrect).

IPWorksZipException

compressData

public byte[] compressData(byte[] data)
                    throws IPWorksZipException
Compresses a byte array.

Compresses the input byte array using the format specified in StreamFormat , and returns the compressed data. The entire contents of the uncompressed data must be specified at one time.

IPWorksZipException

config

public java.lang.String config(java.lang.String configurationString)
                        throws IPWorksZipException
Sets or retrieves a configuration setting.

Config is a generic method available in every bean. It is used to set and retrieve configuration settings for the bean.

Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the bean, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY , you must call Config("PROPERTY=VALUE") , where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY") . The value will be returned as a string.

The bean accepts one or more of the following configuration settings . Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the bean, access to these internal properties is provided through the Config method.

No configuration settings defined.

IPWorksZipException

decompressData

public byte[] decompressData(byte[] data)
                      throws IPWorksZipException
Decompresses a byte array.

Decompresses the input byte array using StreamFormat , and returns the uncompressed data. The entire contents of the compressed data must be specified at one time.

IPWorksZipException

getCompressionStream

public java.io.OutputStream getCompressionStream(java.io.OutputStream baseStream)
                                          throws IPWorksZipException
Creates an output stream used to write compressed data.

GetCompressionStream returns a java.io.OutputStream used to compress data as it is written to an underlying stream. The BaseStream parameter should be the java.io.OutputStream to which the compressed data will be written.

The format ( zlib or gzip ) is selected with the StreamFormat property; zlib is the default. Note that the stream, once created, is independent of the bean.

The return value provides the following standard java.io.OutputStream methods. Please see the official Java documentation for details.

public void close() throws IOException

Closes the stream. Also closes BaseStream if CloseBaseStream is set to true before this stream is created.

public void flush() throws IOException

Flushes the output stream, and forces all data to be compressed and written to the underlying stream. Caution: Flush only when necessary, as repeated flushing may degrade the compression ratio.

public void write(int b) throws IOException

Compresses and writes the byte b to the underlying stream.

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

Compresses and writes the byte array b to the underlying stream.

IPWorksZipException

getDecompressionStream

public java.io.InputStream getDecompressionStream(java.io.InputStream baseStream)
                                           throws IPWorksZipException
Creates an input stream used to read data from a compressed stream.

GetDecompressionStream returns a java.io.InputStream used to read the decompressed data from a compressed stream. The BaseStream parameter should be the java.io.InputStream providing the compressed data.

The format ( zlib or gzip ) is selected with the StreamFormat property; zlib is the default. Note that the stream, once created, is independent of the bean.

The return value provides the following standard java.io.InputStream methods. Please see the official Java documentation for details.

public void close() throws IOException

Closes the stream. Also closes BaseStream if CloseBaseStream is set to true before this stream is created.

public int read() throws IOException

Reads a single byte of data from the input stream. Returns -1 if no data was able to be read.

public int read(byte[] b) throws IOException public int read(byte[] b, int off, int len) throws IOException

Reads decompressed data into the provided byte array, and returns the number of bytes actually read. Returns -1 if the stream was finished.

public long skip(long n) throws IOException

Attempts to skip n bytes of (decompressed) data, and returns the number of bytes actually skipped.

Other methods (such as reset ) are defined, but do nothing special, and will return default values or throw exceptions as defined by the Java API.

IPWorksZipException

addZipstreamEventListener

public void addZipstreamEventListener(ipworkszip.ZipstreamEventListener l)
                               throws java.util.TooManyListenersException
java.util.TooManyListenersException

removeZipstreamEventListener

public void removeZipstreamEventListener(ipworkszip.ZipstreamEventListener l)

IP*Works! ZIP V8

Copyright (c) 2009 /n software inc. - All rights reserved.