org.abstracthorizon.danube.http
Class HTTPBufferedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.abstracthorizon.danube.http.HTTPBufferedOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class HTTPBufferedOutputStream
extends OutputStream

This is buffered http output stream. It knows how to emit chuncked encoding.

Author:
Daniel Sendula

Field Summary
protected  byte[] buffer
          Buffer
protected  int bufferSize
          Buffer size
protected  boolean chunkEncoding
          Chunk encoding
protected  boolean closed
          Is closed
protected  HTTPConnectionImpl connection
          Connection
static String CRLF
          CR, LF
protected  long limitedContentLength
          Content length limit
protected  OutputStream outputStream
          Wrapped output stream
protected  int ptr
          Pointer in the buffer
protected  int sentbytes
          Number of sent bytes
protected  boolean supporessOutput
          Should output be suppressed
 
Constructor Summary
HTTPBufferedOutputStream(HTTPConnectionImpl connection, OutputStream outputStream, int defaultBufferSize)
          Constructor
 
Method Summary
protected  void checkBuffer()
          Checks if buffer is created
 void close()
           
 void flushImpl()
          Implements flushing of the buffer
 int getBufferSize()
          Returns buffer size
 long getLimitedContentLength()
          Returns limited content length
 boolean isChunkEncoding()
          Returns if chunk encoding
 boolean isSupporessOutput()
          Returns true if output should be suppressed
 void resetInternals()
          Resets internals
 void setBufferSize(int size)
          Sets buffer size
 void setChunkEncoding(boolean chunkEncoding)
          Sets chunk encoding
 void setLimitedContentLength(long limitedContentLength)
          Sets limited content length
 void setSupporessOutput(boolean suppressOutput)
          Sets if output should be suppressed or not
 void write(byte[] buf)
           
 void write(byte[] buf, int start, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CRLF

public static final String CRLF
CR, LF

See Also:
Constant Field Values

buffer

protected byte[] buffer
Buffer


ptr

protected int ptr
Pointer in the buffer


connection

protected HTTPConnectionImpl connection
Connection


outputStream

protected OutputStream outputStream
Wrapped output stream


supporessOutput

protected boolean supporessOutput
Should output be suppressed


bufferSize

protected int bufferSize
Buffer size


closed

protected boolean closed
Is closed


limitedContentLength

protected long limitedContentLength
Content length limit


sentbytes

protected int sentbytes
Number of sent bytes


chunkEncoding

protected boolean chunkEncoding
Chunk encoding

Constructor Detail

HTTPBufferedOutputStream

public HTTPBufferedOutputStream(HTTPConnectionImpl connection,
                                OutputStream outputStream,
                                int defaultBufferSize)
Constructor

Parameters:
connection - connection
outputStream - wrapped output stream
defaultBufferSize - default buffer size
Method Detail

resetInternals

public void resetInternals()
Resets internals


setSupporessOutput

public void setSupporessOutput(boolean suppressOutput)
Sets if output should be suppressed or not

Parameters:
suppressOutput - should output be suppressed

isSupporessOutput

public boolean isSupporessOutput()
Returns true if output should be suppressed

Returns:
true if output should be suppressed

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

getLimitedContentLength

public long getLimitedContentLength()
Returns limited content length

Returns:
limited content length

setLimitedContentLength

public void setLimitedContentLength(long limitedContentLength)
Sets limited content length

Parameters:
limitedContentLength - limited 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

checkBuffer

protected void checkBuffer()
                    throws IOException
Checks if buffer is created

Throws:
IOException

flushImpl

public void flushImpl()
               throws IOException
Implements flushing of the buffer

Throws:
IOException

close

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

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] buf,
                  int start,
                  int len)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] buf)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException


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