net.noderunner.http
Class ChunkedOutputStream

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

public class ChunkedOutputStream
extends OutputStream

An OutputStream wrapper that supports the chunked transfer encoding.

Author:
Elias Ross
See Also:
ChunkedInputStream

Constructor Summary
ChunkedOutputStream(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.
 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(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 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 OutputStream
Parameters:
b - The byte to be written
Throws:
IOException - if an input/output error occurs

write

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

Overrides:
write in class OutputStream
Throws:
IOException

write

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

Overrides:
write in class OutputStream
Throws:
IOException

flush

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

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

doneOutput

public void doneOutput()
                throws 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:
IOException

close

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

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

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.