Class ContentLengthOutputStream

java.lang.Object
java.io.OutputStream
org.apache.http.impl.io.ContentLengthOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ContentLengthOutputStream
extends OutputStream
A stream wrapper that closes itself after a defined number of bytes.
Since:
4.0
Version:
$Revision: 560343 $
Author:
Oleg Kalnichevski
  • Constructor Summary

    Constructors
    Constructor Description
    ContentLengthOutputStream​(SessionOutputBuffer out, long contentLength)
    Creates a new length limited stream
  • Method Summary

    Modifier and Type Method Description
    void close()
    Does not close the underlying socket output.
    void flush()
    Flushes this stream.
    void write​(byte[] b)
    Equivalent to write(buffer, 0, buffer.length).
    void write​(byte[] b, int off, int len)
    Writes count bytes from the byte array buffer starting at position offset to this stream.
    void write​(int b)
    Writes a single byte to this stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ContentLengthOutputStream

      public ContentLengthOutputStream​(SessionOutputBuffer out, long contentLength)
      Creates a new length limited stream
      Parameters:
      out - The data transmitter to wrap
      contentLength - The maximum number of bytes that can be written to the stream. Subsequent write operations will be ignored.
      Since:
      4.0
  • Method Details

    • close

      public void close() throws IOException

      Does not close the underlying socket output.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException - If an I/O problem occurs.
    • flush

      public void flush() throws IOException
      Description copied from class: OutputStream
      Flushes this stream. Implementations of this method should ensure that any buffered data is written out. This implementation does nothing.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException - if an error occurs while flushing this stream.
    • write

      public void write​(byte[] b, int off, int len) throws IOException
      Description copied from class: OutputStream
      Writes count bytes from the byte array buffer starting at position offset to this stream.
      Overrides:
      write in class OutputStream
      Parameters:
      b - the buffer to be written.
      off - the start position in buffer from where to get bytes.
      len - the number of bytes from buffer to write to this stream.
      Throws:
      IOException - if an error occurs while writing to this stream.
    • write

      public void write​(byte[] b) throws IOException
      Description copied from class: OutputStream
      Equivalent to write(buffer, 0, buffer.length).
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write​(int b) throws IOException
      Description copied from class: OutputStream
      Writes a single byte to this stream. Only the least significant byte of the integer oneByte is written to the stream.
      Specified by:
      write in class OutputStream
      Parameters:
      b - the byte to be written.
      Throws:
      IOException - if an error occurs while writing to this stream.