net.rim.device.api.compress
Class ZLibInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by net.rim.device.api.compress.ZLibInputStream

public class ZLibInputStream
extends InputStream

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

Sample code

try
{
    InputStream inputStream = new ByteArrayInputStream(compressedData);
    ZLibInputStream zlibInputStream = new ZLibInputStream(inputStream, true);
    byte[] data = new byte[uncompressedSize];
    zlibInputStream.read(data);
}
catch(IOException ioe)
{
}


Constructor Summary
ZLibInputStream(InputStream inputStream)
          Creates a new ZLibInputStream instance (which requires the ZLib header and trailer wrapping to be present - see other constructor).
ZLibInputStream(InputStream inputStream, boolean noWrap)
          Creates a new ZLibInputStream instance.
ZLibInputStream(InputStream inputStream, boolean noWrap, int workingBufferSize)
          Creates a new ZLibInputStream instance.
 
Method Summary
 int available()
          Retreives number of bytes which can be read from this stream without blocking.
 void close()
          Closes this stream.
 int read()
          Retrieves one byte from this input stream.
 int read(byte[] buffer, int bufferOffset, int bufferLength)
          Read specified number of bytes from this stream.
 long skip(long n)
          Skips over and discards n bytes of data from this input.
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Constructor Detail

ZLibInputStream

public ZLibInputStream(InputStream inputStream)
Creates a new ZLibInputStream instance (which requires the ZLib header and trailer wrapping to be present - see other constructor).

Parameters:
inputStream - Underlying input stream to use.

ZLibInputStream

public ZLibInputStream(InputStream inputStream,
                       boolean noWrap)
Creates a new ZLibInputStream instance.

If noWrap is true, the decompressor will assume that the ZLib 16 bit header and the 32 bit trailer checksum are not included in the underlying input stream. This mode is necessary for PKZip/Info-ZIP and GZIP compatibility.

Parameters:
inputStream - Underlying input stream to use.
noWrap - If true, the header and trailer are not present in the underlying input stream.

ZLibInputStream

public ZLibInputStream(InputStream inputStream,
                       boolean noWrap,
                       int workingBufferSize)
Creates a new ZLibInputStream instance.

If noWrap is true, the decompressor will assume that the ZLib 16 bit header and the 32 bit trailer checksum are not included in the underlying input stream. This mode is necessary for PKZip/Info-ZIP and GZIP compatibility.

Parameters:
inputStream - Underlying input stream to use.
noWrap - If true, the header and trailer are not present in the underlying input stream.
workingBufferSize - The buffer size to use for the read window; cannot be less than 1024.
Since:
BlackBerry API 4.1.0


Method Detail

read

public int read()
         throws IOException
Retrieves one byte from this input stream.

Specified by:
read in class InputStream
Returns:
Byte of decompressed data, or -1 if no more data in this stream.

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

read

public int read(byte[] buffer,
                int bufferOffset,
                int bufferLength)
         throws IOException
Read specified number of bytes from this stream.

Overrides:
read in class InputStream
Parameters:
buffer - Buffer to contain data; must be large enough to contain desired number of bytes.
bufferOffset - First element in output parameter buffer at which to begin writing decoded data; if not 0, then output parameter buffer must be at least bufferOffset + bufferLength elements long.
bufferLength - Number of bytes to read from this stream.
Returns:
0 if length of output parameter byte array is zero; otherwise, the number of bytes actually read into the buffer. If no more data was available when you invoked this method, it returns -1.
Throws:
IOException - If an I/O error occurs.
See Also:
InputStream.read()

available

public int available()
              throws IOException
Retreives number of bytes which can be read from this stream without blocking.

Overrides:
available in class InputStream
Returns:
Number of bytes availble to be read without blocking.

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

close

public void close()
           throws IOException
Closes this stream.

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

skip

public long skip(long n)
          throws IOException
Skips over and discards n bytes of data from this input.

Overrides:
skip in class InputStream
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException - if an I/O error occurs.
Since:
BlackBerry API 5.0.0





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.