HTTPClient
Class RespInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--HTTPClient.RespInputStream
All Implemented Interfaces:
GlobalConstants

final class RespInputStream
extends java.io.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
TypeField
(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
 
Fields inherited from interface HTTPClient.GlobalConstants
CD_0, CD_CHUNKED, CD_CLOSE, CD_CONTLEN, CD_HDRS, CD_MP_BR, CD_NONE, HTTP, HTTP_1_0, HTTP_1_1, HTTP_NG, HTTPS, SHTTP
 
Constructor Summary
(package private) RespInputStream(StreamDemultiplexor demux, ResponseHandler resph)
           
 
Method Summary
TypeMethod
(package private) static void ()
           
 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
Constructor Detail

RespInputStream

RespInputStream(StreamDemultiplexor demux,
                ResponseHandler resph)
Method Detail

static void ()

read

public int read()
         throws java.io.IOException
Reads a single byte.
Overrides:
read in class java.io.InputStream
Returns:
the byte read, or -1 if EOF.
Throws:
java.io.IOException - if any exception occured on the connection.

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads len bytes into b, starting at offset off.
Overrides:
read in class java.io.InputStream
Returns:
the number of bytes actually read, or -1 if EOF.
Throws:
java.io.IOException - if any exception occured on the connection.

skip

public long skip(long num)
          throws java.io.IOException
skips num bytes.
Overrides:
skip in class java.io.InputStream
Returns:
the number of bytes actually skipped.
Throws:
java.io.IOException - if any exception occured on the connection.

available

public int available()
              throws java.io.IOException
gets the number of bytes available for reading without blocking.
Overrides:
available in class java.io.InputStream
Returns:
the number of bytes available.
Throws:
java.io.IOException - if any exception occured on the connection.

close

public void close()
           throws java.io.IOException
closes the stream.
Overrides:
close in class java.io.InputStream
Throws:
if - any exception occured on the connection before or during close.

finalize

protected void finalize()
                 throws java.lang.Throwable
A safety net to clean up.
Overrides:
finalize in class java.lang.Object

readAll

void readAll(int timeout)
       throws java.io.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:
java.io.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.