net.rim.device.api.compress
Class ZLibOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by net.rim.device.api.compress.ZLibOutputStream

public class ZLibOutputStream
extends OutputStream

Output stream for writing a data stream compressed with the ZLib algorithm (RFC 1950, RFC 1951).

Sample code

try
{
    ByteArrayOutputStream bufferOut = new ByteArrayOutputStream();
    ZLibOutputStream compressedOut = new ZLibOutputStream( bufferOut );
    compressedOut.write( data, offset, length );
    compressedOut.close();
}
catch(IOException ioe)
{
}


Field Summary
static int COMPRESSION_BEST
           
static int COMPRESSION_NONE
           
static int MAX_LOG2_WINDOW_LENGTH
           
static int MIN_LOG2_WINDOW_LENGTH
           
 
Constructor Summary
ZLibOutputStream(OutputStream outputStream)
          Creates a new ZLibOutputStream instance (the header and trailer wrapping will be generated, and the maximum window length may be used - see other constructors).
ZLibOutputStream(OutputStream outputStream, boolean noWrap)
          Creates a new ZLibOutputStream instance (the maximum window length may be used - see other constructors).
ZLibOutputStream(OutputStream outputStream, boolean noWrap, int maxLog2WindowLength)
          Creates a new ZLibOutputStream instance.
ZLibOutputStream(OutputStream outputStream, boolean noWrap, int maxLog2WindowLength, int compressionValue)
          Creates a new ZLibOutputStream instance.
 
Method Summary
 void close()
          Closes this output stream.
 void flush()
          Flushes this stream, writing out any remaining buffered data.
 void write(byte[] data, int dataOffset, int dataLength)
          Writes some bytes from byte array to this stream.
 void write(int data)
          Writes a byte to this stream.
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Field Detail

MIN_LOG2_WINDOW_LENGTH

public static final int MIN_LOG2_WINDOW_LENGTH
See Also:
Constant Field Values

MAX_LOG2_WINDOW_LENGTH

public static final int MAX_LOG2_WINDOW_LENGTH
See Also:
Constant Field Values

COMPRESSION_NONE

public static final int COMPRESSION_NONE
See Also:
Constant Field Values
Since:
BlackBerry API 4.1.0

COMPRESSION_BEST

public static final int COMPRESSION_BEST
See Also:
Constant Field Values
Since:
BlackBerry API 4.1.0


Constructor Detail

ZLibOutputStream

public ZLibOutputStream(OutputStream outputStream)
Creates a new ZLibOutputStream instance (the header and trailer wrapping will be generated, and the maximum window length may be used - see other constructors).

Note this constructor provides no compression; this is done to be compatible with prior implementations of this class. Use the alternate constructor which accepts the compression value to achieve compression.

Parameters:
outputStream - Underlying output stream to use.

ZLibOutputStream

public ZLibOutputStream(OutputStream outputStream,
                        boolean noWrap)
Creates a new ZLibOutputStream instance (the maximum window length may be used - see other constructors).

If noWrap is true, the compressor will not generate the ZLib 16 bit header and the 32 bit trailer checksum. This mode is necessary for PKZip/Info-ZIP and GZIP compatibility.

Note this constructor provides no compression; this is done to be compatible with prior implementations of this class. Use the alternate constructor which accepts the compression value to achieve compression.

Parameters:
outputStream - Underlying output stream to use.
noWrap - If true, the header and trailer will not be generated.

ZLibOutputStream

public ZLibOutputStream(OutputStream outputStream,
                        boolean noWrap,
                        int maxLog2WindowLength)
Creates a new ZLibOutputStream instance.

If noWrap is true, the compressor will not generate the ZLib 16 bit header and the 32 bit trailer checksum. This mode is necessary for PKZip/Info-ZIP and GZIP compatibility.

maxLog2WindowLength can range from 8 to 15. Note: if the value was 10, the window length would be 2^10 = 1024 bytes. This parameter can be used to limit the window length for those decompressors which are not capable of dealing with the maximum window length (2^15 -> 32KB). Note, the actual window length may be smaller.

Note this constructor provides no compression; this is done to be compatible with prior implementations of this class. Use the alternate constructor which accepts the compression value to achieve compression.

Parameters:
outputStream - Underlying output stream to use.
noWrap - If true, the header and trailer will not be generated.
maxLog2WindowLength - maximum window length.

ZLibOutputStream

public ZLibOutputStream(OutputStream outputStream,
                        boolean noWrap,
                        int maxLog2WindowLength,
                        int compressionValue)
Creates a new ZLibOutputStream instance.

If noWrap is true, the compressor will not generate the ZLib 16 bit header and the 32 bit trailer checksum. This mode is necessary for PKZip/Info-ZIP and GZIP compatibility.

maxLog2WindowLength can range from 8 to 15. Note: if the value was 10, the window length would be 2^10 = 1024 bytes. This parameter can be used to limit the window length for those decompressors which are not capable of dealing with the maximum window length (2^15 -> 32KB). Note, the actual window length may be smaller.

Parameters:
outputStream - Underlying output stream to use.
noWrap - If true, the header and trailer will not be generated.
maxLog2WindowLength - maximum window length.
compressionValue - 0 to 9 representing compression value; 0 being none; 9 being best.
Since:
BlackBerry API 4.1.0


Method Detail

write

public void write(int data)
           throws IOException
Writes a byte to this stream.

Specified by:
write in class OutputStream
Parameters:
data - the byte to be written

Throws:
IOException - If an I/O error occurs.

write

public void write(byte[] data,
                  int dataOffset,
                  int dataLength)
           throws IOException
Writes some bytes from byte array to this stream.

Invoke this method to compress, and then write, some bytes contained in the input array to this stream.

Overrides:
write in class OutputStream
Parameters:
data - Data to write.
dataOffset - First byte from provided array to compress and write.
dataLength - Number of bytes from provided array to compress and write.
Throws:
IOException - If an I/O error occurs.

flush

public void flush()
           throws IOException
Flushes this stream, writing out any remaining buffered data.

Overrides:
flush in class OutputStream
Throws:
IOException - If an I/O error occurs.

close

public void close()
           throws IOException
Closes this output stream.

Overrides:
close in class OutputStream
Throws:
IOException - If an I/O error occurs.





Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.