org.abstracthorizon.danube.http
Class HTTPBufferedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.abstracthorizon.danube.http.HTTPBufferedInputStream
All Implemented Interfaces:
Closeable

public class HTTPBufferedInputStream
extends InputStream

This is buffered http input stream. It knows how to read chuncked encoding.

Author:
Daniel Sendula

Field Summary
protected  byte[] buffer
          Buffer
protected  int bufferSize
          Buffer size
protected  boolean chunkEncoding
          Chunk encoding
protected  int chunkSize
          Current chunk size
protected  boolean closed
          Is closed
protected  long contentLength
          Content length limit
static int DEFAULT_BUFFER_SIZE
          Default buffer size to be used when operating in not buffered mode (close and skip methods, for instance)
protected  InputStream inputStream
          Input stream
protected  int len
          Amount of bytes in the buffer
protected  int mark
          Mark
protected  int ptr
          Pointer in the buffer
protected  int readbytes
          Number of sent bytes
 
Constructor Summary
HTTPBufferedInputStream(InputStream inputStream, int defaultBufferSize)
          Constructor
 
Method Summary
 int available()
           
protected  void checkBuffer()
          Checks if buffer is empty and fills it in if needed
 void close()
           
 int getBufferSize()
          Returns buffer size
 long getContentLength()
          Returns limited content length
 boolean isChunkEncoding()
          Returns if chunk encoding
 void mark(int i)
           
 boolean markSupported()
           
 int read()
           
 int read(byte[] buf)
           
 int read(byte[] buf, int off, int l)
           
protected  int readChunkSize()
          Read chunk size
 void reset()
           
 void resetInternals()
          Resets internals
 void setBufferSize(int size)
          Sets buffer size
 void setChunkEncoding(boolean chunkEncoding)
          Sets chunk encoding
 void setContentLength(long contentLength)
          Sets content length
 long skip(long l)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
Default buffer size to be used when operating in not buffered mode (close and skip methods, for instance)

See Also:
Constant Field Values

buffer

protected byte[] buffer
Buffer


ptr

protected int ptr
Pointer in the buffer


len

protected int len
Amount of bytes in the buffer


mark

protected int mark
Mark


inputStream

protected InputStream inputStream
Input stream


bufferSize

protected int bufferSize
Buffer size


closed

protected boolean closed
Is closed


contentLength

protected long contentLength
Content length limit


readbytes

protected int readbytes
Number of sent bytes


chunkEncoding

protected boolean chunkEncoding
Chunk encoding


chunkSize

protected int chunkSize
Current chunk size

Constructor Detail

HTTPBufferedInputStream

public HTTPBufferedInputStream(InputStream inputStream,
                               int defaultBufferSize)
Constructor

Parameters:
intputStream - wrapped input stream
defaultBufferSize - default buffer size
Method Detail

resetInternals

public void resetInternals()
Resets internals


getBufferSize

public int getBufferSize()
Returns buffer size

Returns:
buffer size

setBufferSize

public void setBufferSize(int size)
Sets buffer size

Parameters:
size - buffer size
Throws:
IOException - io exception

getContentLength

public long getContentLength()
Returns limited content length

Returns:
limited content length

setContentLength

public void setContentLength(long contentLength)
Sets content length

Parameters:
contentLength - content length

isChunkEncoding

public boolean isChunkEncoding()
Returns if chunk encoding

Returns:
if chunk encoding

setChunkEncoding

public void setChunkEncoding(boolean chunkEncoding)
Sets chunk encoding

Parameters:
chunkEncoding - is chunk encoding

readChunkSize

protected int readChunkSize()
                     throws IOException
Read chunk size

Returns:
chunk size
Throws:
IOException

checkBuffer

protected void checkBuffer()
                    throws IOException
Checks if buffer is empty and fills it in if needed

Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] buf)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] buf,
                int off,
                int l)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

skip

public long skip(long l)
          throws IOException
Overrides:
skip in class InputStream
Throws:
IOException

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Throws:
IOException

mark

public void mark(int i)
Overrides:
mark in class InputStream

reset

public void reset()
           throws IOException
Overrides:
reset in class InputStream
Throws:
IOException

markSupported

public boolean markSupported()
Overrides:
markSupported in class InputStream


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.