net.noderunner.http
Class LimitedOutputStream

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

public class LimitedOutputStream
extends OutputStream

An OutputStream wrapper which allows only a certain number of bytes to be output. This is used in conjunction writing HTTP requests or responses with supplied Content-Length headers. This stream is unsynchronized.

Author:
Elias Ross
See Also:
LimitedInputStream

Constructor Summary
LimitedOutputStream(OutputStream stream, int lengthLimit)
          Constructs a limited output stream.
 
Method Summary
 void close()
          Closes the underlying output stream.
 void flush()
          Flushes the underlying output stream.
 String toString()
          Returns a debug string.
 void write(byte[] b, int off, int len)
          Writes up to len bytes of data to the output stream, possibly less if the write limit is reached.
 void write(int b)
          Writes a byte of data to the output stream, possibly does nothing if the write limit is reached.
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LimitedOutputStream

public LimitedOutputStream(OutputStream stream,
                           int lengthLimit)
Constructs a limited output stream.

Parameters:
stream - must be non-null.
lengthLimit - limit of bytes of output.
Method Detail

close

public void close()
           throws IOException
Closes the underlying output stream.

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

flush

public void flush()
           throws IOException
Flushes the underlying output stream.

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

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes up to len bytes of data to the output stream, possibly less if the write limit is reached.

Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(int b)
           throws IOException
Writes a byte of data to the output stream, possibly does nothing if the write limit is reached.

Specified by:
write in class OutputStream
Throws:
IOException

toString

public String toString()
Returns a debug string.

Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.