io.undertow.io

## Class UndertowOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - io.undertow.io.UndertowOutputStream

All Implemented Interfaces:
  BufferWritableOutputStream, Closeable, Flushable, AutoCloseable

    public class UndertowOutputStream
    extends OutputStream
    implements BufferWritableOutputStream

Buffering output stream that wraps a channel.

This stream delays channel creation, so if a response will fit in the buffer it is not necessary to set the content length header.

Author:
  Stuart Douglas

### Constructor Summary

Constructors
Constructor and Description
`UndertowOutputStream(HttpServerExchange exchange)` Construct a new instance.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `close()`
`void` `flush()`
`long` `getBytesWritten()`
`void` `resetBuffer()` If the response has not yet been written to the client this method will clear the streams buffer, invalidating any content that has already been written.
`void` `transferFrom(FileChannel source)`
`void` `write(byte[] b)`
`void` `write(byte[] b, int off, int len)`
`void` `write(ByteBuffer byteBuffer)`
`void` `write(ByteBuffer[] buffers)`
`void` `write(int b)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### UndertowOutputStream

    public UndertowOutputStream(HttpServerExchange exchange)

Construct a new instance. No write timeout is configured.

Parameters:
  `exchange` - The exchange

### Method Detail

#### resetBuffer

    public void resetBuffer()

If the response has not yet been written to the client this method will clear the streams buffer, invalidating any content that has already been written. If any content has already been sent to the client then this method will throw and IllegalStateException

Throws:
  `IllegalStateException` - If the response has been committed

#### getBytesWritten

    public long getBytesWritten()

#### write

    public void write(int b)
               throws IOException

Specified by:
  `write` in class `OutputStream`
Throws:
  `IOException`

#### write

    public void write(byte[] b)
               throws IOException

Overrides:
  `write` in class `OutputStream`
Throws:
  `IOException`

#### write

    public void write(byte[] b,
                      int off,
                      int len)
               throws IOException

Overrides:
  `write` in class `OutputStream`
Throws:
  `IOException`

#### write

    public void write(ByteBuffer[] buffers)
               throws IOException

Specified by:
  `write` in interface `BufferWritableOutputStream`
Throws:
  `IOException`

#### write

    public void write(ByteBuffer byteBuffer)
               throws IOException

Specified by:
  `write` in interface `BufferWritableOutputStream`
Throws:
  `IOException`

#### flush

    public void flush()
               throws IOException

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

#### transferFrom

    public void transferFrom(FileChannel source)
                      throws IOException

Specified by:
  `transferFrom` in interface `BufferWritableOutputStream`
Throws:
  `IOException`

#### close

    public void close()
               throws IOException

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