rabbit.io
Class HTTPInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byjava.io.DataInputStream
              extended byrabbit.io.HTTPInputStream
All Implemented Interfaces:
java.io.DataInput

public class HTTPInputStream
extends java.io.DataInputStream

This is an extended DataInputStream suitable for reading data from the web. It handles chunked encoding etc. If the underlying input is chunked this class will throw away any trailing footer.


Constructor Summary
HTTPInputStream(java.io.InputStream is)
          Create a new HTTPInputStream on the underlying stream.
 
Method Summary
 boolean chunked()
          Get the chunked value.
 void close()
           
 long dataSize()
          Get the size of the page being read.
 java.io.InputStream getChunkStream()
          Get the chunked page.
 boolean getKeepAlive()
          Get the keep alive value.
 void readCRLF()
          Read of an CR LF combination.
 HTTPHeader readHTTPHeader()
          Read a HTTPHeader of this stream.
 void setKeepAlive(boolean keepalive)
          Set the keep alive value to currentkeepalive & keepalive
 
Methods inherited from class java.io.DataInputStream
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTF, skipBytes
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTTPInputStream

public HTTPInputStream(java.io.InputStream is)
Create a new HTTPInputStream on the underlying stream.

Parameters:
is - the underlying stream
Method Detail

readHTTPHeader

public HTTPHeader readHTTPHeader()
                          throws java.io.IOException
Read a HTTPHeader of this stream. If data is chunked the whole page will be read in so to get it use the getChunkStream. something like this HTTPHeader header = readHeader (); if (chunked) { contentStream = getChunkStream (); }

Returns:
a new HTTPHeader read from the stream.
Throws:
java.io.IOException - if the HTTPHeader could not be read correctly.

getKeepAlive

public boolean getKeepAlive()
Get the keep alive value.

Returns:
if this stream is in keepalive mode.

setKeepAlive

public void setKeepAlive(boolean keepalive)
Set the keep alive value to currentkeepalive & keepalive

Parameters:
keepalive - the new keepalive value.

chunked

public boolean chunked()
Get the chunked value.

Returns:
true if the last read HTTPHeader was chunked.

dataSize

public long dataSize()
Get the size of the page being read.

Returns:
the size of the page being read or -1 if unknown.

readCRLF

public void readCRLF()
              throws java.io.IOException
Read of an CR LF combination.

Throws:
java.io.IOException - if the CR LF combination could not be read correctly.

getChunkStream

public java.io.InputStream getChunkStream()
Get the chunked page.

Returns:
an InputStream to the previously read chunked pagel.

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException