net.noderunner.http
Class ChunkedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by net.noderunner.http.ChunkedOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class ChunkedOutputStream
extends java.io.OutputStream

An OutputStream wrapper that supports the chunked transfer encoding.

Author:
Elias Ross
See Also:
ChunkedInputStream

Constructor Summary
ChunkedOutputStream(java.io.OutputStream stream)
          Constructs an output stream wrapping the given stream.
 
Method Summary
 void close()
          Closes this output stream, calling doneOutput once before closing.
 void doneOutput()
          This method differs from close as it merely writes the final chunk and does not close the underlying output stream.
 void flush()
          Flushes this output stream.
 java.lang.String toString()
           
 void write(byte[] b)
          Writes the specified byte array.
 void write(byte[] b, int off, int len)
          Writes the specified byte array.
 void write(int b)
          Writes the specified byte to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChunkedOutputStream

public ChunkedOutputStream(java.io.OutputStream stream)
Constructs an output stream wrapping the given stream.

Parameters:
stream - wrapped output stream. Must be non-null.
Method Detail

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to the output stream. Note: Of course, this isn't very efficient, as we have to send seven bytes of header data as well.

Specified by:
write in class java.io.OutputStream
Parameters:
b - The byte to be written
Throws:
java.io.IOException - if an input/output error occurs

write

public void write(byte[] b)
           throws java.io.IOException
Writes the specified byte array.

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Writes the specified byte array.

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flushes this output stream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

doneOutput

public void doneOutput()
                throws java.io.IOException
This method differs from close as it merely writes the final chunk and does not close the underlying output stream. This has no effect if this method was called already.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes this output stream, calling doneOutput once before closing.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2009. All Rights Reserved.