HTTPClient
Class RespInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byHTTPClient.RespInputStream
All Implemented Interfaces:
GlobalConstants

final class RespInputStream
extends InputStream
implements GlobalConstants

This is the InputStream that gets returned to the user. The extensions consist of the capability to have the data pushed into a buffer if the stream demux needs to.

Since:
V0.2

Field Summary
static int CD_0
           
static int CD_CHUNKED
           
static int CD_CLOSE
           
static int CD_CONTLEN
           
static int CD_HDRS
           
static int CD_MP_BR
           
static int CD_NONE
          Content delimiters
(package private)  boolean closed
          signals that the user has closed the stream and will therefore not read any further data
(package private)  int count
          the total number of bytes of entity data read from the demux so far
static int HTTP
          possible http protocols we (might) handle
static int HTTP_1_0
          some known http versions
static int HTTP_1_1
           
static int HTTP_NG
           
static int HTTPS
           
static int SHTTP
           
 
Constructor Summary
(package private) RespInputStream(StreamDemultiplexor demux, ResponseHandler resph)
           
 
Method Summary
 int available()
          gets the number of bytes available for reading without blocking.
 void close()
          closes the stream.
(package private)  void dontTruncate()
          Sometime the full response body must be read, i.e.
protected  void finalize()
          A safety net to clean up.
 int read()
          Reads a single byte.
 int read(byte[] b, int off, int len)
          Reads len bytes into b, starting at offset off.
(package private)  void readAll(int timeout)
          Reads all remainings data into buffer.
 long skip(long num)
          skips num bytes.
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

closed

boolean closed
signals that the user has closed the stream and will therefore not read any further data


count

int count
the total number of bytes of entity data read from the demux so far


HTTP

public static final int HTTP
possible http protocols we (might) handle

See Also:
Constant Field Values

HTTPS

public static final int HTTPS
See Also:
Constant Field Values

SHTTP

public static final int SHTTP
See Also:
Constant Field Values

HTTP_NG

public static final int HTTP_NG
See Also:
Constant Field Values

HTTP_1_0

public static final int HTTP_1_0
some known http versions

See Also:
Constant Field Values

HTTP_1_1

public static final int HTTP_1_1
See Also:
Constant Field Values

CD_NONE

public static final int CD_NONE
Content delimiters

See Also:
Constant Field Values

CD_HDRS

public static final int CD_HDRS
See Also:
Constant Field Values

CD_0

public static final int CD_0
See Also:
Constant Field Values

CD_CLOSE

public static final int CD_CLOSE
See Also:
Constant Field Values

CD_CONTLEN

public static final int CD_CONTLEN
See Also:
Constant Field Values

CD_CHUNKED

public static final int CD_CHUNKED
See Also:
Constant Field Values

CD_MP_BR

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

RespInputStream

RespInputStream(StreamDemultiplexor demux,
                ResponseHandler resph)
Method Detail

read

public int read()
         throws IOException
Reads a single byte.

Returns:
the byte read, or -1 if EOF.
Throws:
IOException - if any exception occured on the connection.

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads len bytes into b, starting at offset off.

Returns:
the number of bytes actually read, or -1 if EOF.
Throws:
IOException - if any exception occured on the connection.

skip

public long skip(long num)
          throws IOException
skips num bytes.

Returns:
the number of bytes actually skipped.
Throws:
IOException - if any exception occured on the connection.

available

public int available()
              throws IOException
gets the number of bytes available for reading without blocking.

Returns:
the number of bytes available.
Throws:
IOException - if any exception occured on the connection.

close

public void close()
           throws IOException
closes the stream.

Throws:
if - any exception occured on the connection before or during close.
IOException

finalize

protected void finalize()
                 throws Throwable
A safety net to clean up.

Throws:
Throwable

readAll

void readAll(int timeout)
       throws IOException
Reads all remainings data into buffer. This is used to force a read of upstream responses.

This is probably the most tricky and buggy method around. It's the only one that really violates the strict top-down method invocation from the Response through the ResponseStream to the StreamDemultiplexor. This means we need to be awfully careful about what is synchronized and what parameters are passed to whom.

Parameters:
timeout - the timeout to use for reading from the demux
Throws:
IOException - If any exception occurs while reading stream.

dontTruncate

void dontTruncate()
Sometime the full response body must be read, i.e. the connection may not be closed prematurely (by us). Currently this is needed when the chunked encoding with trailers is used in a response.