net.noderunner.http
Class LimitedOutputStream

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

public class LimitedOutputStream
extends java.io.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(java.io.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.
 java.lang.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(java.io.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 java.io.IOException
Closes the underlying output stream.

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

flush

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

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

write

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

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

write

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

Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

toString

public java.lang.String toString()
Returns a debug string.

Overrides:
toString in class java.lang.Object


Copyright © 2010. All Rights Reserved.