net.rim.device.api.compress
Class GZIPInputStream

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

public class GZIPInputStream
extends InputStream

Input stream for reading a data stream compressed with the GZIP algorithm (RFC 1952).


Sample code

Example 1:

try
{
    InputStream inputStream = httpConnection.openInputStream();
    GZIPInputStream gzis = new GZIPInputStream(inputStream);
    StringBuffer sb = new StringBuffer();
   
    char c;
    while ((c = (char)gzis.read()) != -1)
    {
        sb.append(c);
    }
   
    String data = sb.toString();
   
    gzis.close();
}
catch(IOException ioe)
{
}

Example 2:

byte[] resource = ...
GZIPInputStream gin = new GZIPInputStream(new ByteArrayInputStream(resource));
byte[] bytes = IOUtilities.streamToBytes(gin);
DataBuffer db = new DataBuffer();
db.setData(bytes, 0, bytes.length);


Constructor Summary
GZIPInputStream(InputStream inputStream)
          Creates a new GZIPInputStream instance.
GZIPInputStream(InputStream inputStream, int workingBufferSize)
          Creates a new GZIPInputStream 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

GZIPInputStream

public GZIPInputStream(InputStream inputStream)
Creates a new GZIPInputStream instance.

Parameters:
inputStream - Underlying input stream to use.

GZIPInputStream

public GZIPInputStream(InputStream inputStream,
                       int workingBufferSize)
Creates a new GZIPInputStream instance.

Parameters:
inputStream - Underlying input stream to use.
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-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal