org.mortbay.http
Class ChunkableOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.FilterOutputStream
              |
              +--org.mortbay.http.ChunkableOutputStream

public class ChunkableOutputStream
extends java.io.FilterOutputStream

HTTP Chunkable OutputStream. Acts as a BufferedOutputStream until setChunking(true) is called. Once chunking is enabled, the raw stream is chunk encoded as per RFC2616. Implements the following HTTP and Servlet features:

This class is not synchronized and should be synchronized explicitly if an instance is used by multiple threads.

Version:
$Id: ChunkableOutputStream.java,v 1.1 2001/09/02 01:13:08 gregwilkins Exp $
Author:
Greg Wilkins

Field Summary
static java.lang.Class[] __filterArg
           
 
Constructor Summary
ChunkableOutputStream(java.io.OutputStream outputStream)
          Constructor.
 
Method Summary
 void addObserver(OutputObserver observer)
          Add an Output Observer.
 void close()
          Close the stream.
 void flush()
           
 void flush(boolean endChunking)
           
 int getBufferCapacity()
          Get the output buffer capacity.
 int getBytesWritten()
           
 java.io.OutputStream getRawStream()
          Get the raw stream.
 java.io.Writer getRawWriter()
          Get Writer for the raw stream.
 void insertFilter(java.lang.reflect.Constructor filter, java.lang.Object[] args)
          Insert FilterOutputStream.
 boolean isChunking()
          Get chunking mode
 boolean isCommitted()
          Has any data been sent from this stream.
 boolean isNullOutput()
          is the output Nulled?
 boolean isWritten()
          Has any data been written to the stream.
 void nullOutput()
          Null the output.
 void print(java.lang.Object o)
           
 void println()
           
 void println(java.lang.Object o)
           
 void resetBuffer()
          Reset Buffered output.
 void resetStream()
          Reset the stream.
 void setBufferCapacity(int capacity)
          Set the output buffer capacity.
 void setChunking()
          Set chunking mode.
 void setTrailer(HttpFields trailer)
          Set the trailer to send with a chunked close.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(java.io.InputStream in, int len)
           
 void write(int b)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__filterArg

public static final java.lang.Class[] __filterArg
Constructor Detail

ChunkableOutputStream

public ChunkableOutputStream(java.io.OutputStream outputStream)
Constructor.
Parameters:
outputStream - The outputStream to buffer or chunk to.
Method Detail

getRawStream

public java.io.OutputStream getRawStream()
Get the raw stream. A stream without filters or chunking is returned.
Returns:
Raw OutputStream.

getRawWriter

public java.io.Writer getRawWriter()
Get Writer for the raw stream. A writer without filters or chunking is returned, which uses the 8859-1 encoding. The converted bytes from this writer will be writen to the rawStream when writeRawWriter() is called. These methods allow Character encoded data to be mixed with raw data on the same stream without excessive buffering or flushes.
Returns:
Raw Writer

isWritten

public boolean isWritten()
Has any data been written to the stream.
Returns:
True if write has been called.

isCommitted

public boolean isCommitted()
Has any data been sent from this stream.
Returns:
True if buffer has been flushed to destination.

getBufferCapacity

public int getBufferCapacity()
Get the output buffer capacity.
Returns:
Buffer capacity in bytes.

setBufferCapacity

public void setBufferCapacity(int capacity)
                       throws java.lang.IllegalStateException
Set the output buffer capacity. Note that this is the minimal buffer capacity and that installed filters may perform their own buffering and are likely to change the size of the output.
Parameters:
capacity - Minimum buffer capacity in bytes
Throws:
java.lang.IllegalStateException - If output has been written.

getBytesWritten

public int getBytesWritten()

resetBuffer

public void resetBuffer()
                 throws java.lang.IllegalStateException
Reset Buffered output. If no data has been committed, the buffer output is discarded and the filters may be reinitialized.
Throws:
java.lang.IllegalStateException -  
Problem - with observer notification.

addObserver

public void addObserver(OutputObserver observer)
Add an Output Observer. Output Observers get notified of significant events on the output stream. They are removed when the stream is closed.
Parameters:
observer - The observer.

nullOutput

public void nullOutput()
                throws java.io.IOException
Null the output. All output written is discarded until the stream is reset. Used for HEAD requests.

isNullOutput

public boolean isNullOutput()
                     throws java.io.IOException
is the output Nulled?

setChunking

public void setChunking()
                 throws java.io.IOException
Set chunking mode.

resetStream

public void resetStream()
                 throws java.lang.IllegalStateException
Reset the stream. Turn disable all filters.
Throws:
java.lang.IllegalStateException - The stream cannot be reset if chunking is enabled.

isChunking

public boolean isChunking()
Get chunking mode

insertFilter

public void insertFilter(java.lang.reflect.Constructor filter,
                         java.lang.Object[] args)
                  throws java.lang.InstantiationException,
                         java.lang.reflect.InvocationTargetException,
                         java.lang.IllegalAccessException
Insert FilterOutputStream. Place a Filtering OutputStream into this stream, but before the chunking stream.
Parameters:
filter - The Filter constructor. It must take an OutputStream as the first arguement.
arg - Optional argument array to pass to filter constructor. The first element of the array is replaced with the current output stream.

setTrailer

public void setTrailer(HttpFields trailer)
Set the trailer to send with a chunked close.
Parameters:
trailer -  

write

public void write(int b)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream

flush

public void flush()
           throws java.io.IOException
Overrides:
flush in class java.io.FilterOutputStream

flush

public void flush(boolean endChunking)
           throws java.io.IOException

close

public void close()
           throws java.io.IOException
Close the stream. In chunking mode, the underlying stream is not closed. All filters are closed and discarded.
Overrides:
close in class java.io.FilterOutputStream
Throws:
java.io.IOException -  

write

public void write(java.io.InputStream in,
                  int len)
           throws java.io.IOException

println

public void println()
             throws java.io.IOException

println

public void println(java.lang.Object o)
             throws java.io.IOException

print

public void print(java.lang.Object o)
           throws java.io.IOException


Copyright © 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.