Package org.springframework.web.servlet.function

# Interface ServerResponse.StreamBuilder

Enclosing interface:
  ServerResponse

public static interface ServerResponse.StreamBuilder
Defines a builder for a streaming response body.

Since:
  6.2

## Method Summary

Modifier and Type
Method
Description
`void`
`complete()`
Completes the stream.
`void`
`error(Throwable t)`
Completes the stream with the given error.
`void`
`flush()`
Flush the buffered response stream content to the network.
`ServerResponse.StreamBuilder`
`onComplete(Runnable onCompletion)`
Register a callback to be invoked when the request completes.
`ServerResponse.StreamBuilder`
`onError(Consumer<Throwable> onError)`
Register a callback to be invoked when an error occurs during processing.
`ServerResponse.StreamBuilder`
`onTimeout(Runnable onTimeout)`
Register a callback to be invoked when a request times out.
`ServerResponse.StreamBuilder`
`write(Object object)`
Write the given object to the response stream, without flushing.
`ServerResponse.StreamBuilder`
`write(Object object, org.springframework.http.MediaType mediaType)`
Write the given object to the response stream, without flushing.

## Method Details

### error

void error(Throwable t)
Completes the stream with the given error.

The throwable is dispatched back into Spring MVC, and passed to its exception handling mechanism. Since the response has been committed by this point, the response status can not change.

Parameters:
  `t` - the throwable to dispatch

### complete

void complete()
Completes the stream.

### onTimeout

ServerResponse.StreamBuilder onTimeout(Runnable onTimeout)
Register a callback to be invoked when a request times out.

Parameters:
  `onTimeout` - the callback to invoke on timeout
Returns:
  this builder

### onError

ServerResponse.StreamBuilder onError(Consumer<Throwable> onError)
Register a callback to be invoked when an error occurs during processing.

Parameters:
  `onError` - the callback to invoke on error
Returns:
  this builder

### onComplete

ServerResponse.StreamBuilder onComplete(Runnable onCompletion)
Register a callback to be invoked when the request completes.

Parameters:
  `onCompletion` - the callback to invoked on completion
Returns:
  this builder

### write

ServerResponse.StreamBuilder write(Object object) throws IOException
Write the given object to the response stream, without flushing. Strings will be sent as UTF-8 encoded bytes, byte arrays will be sent as-is, and other objects will be converted into JSON using message converters.

Parameters:
  `object` - the object to send as data
Returns:
  this builder
Throws:
  `IOException` - in case of I/O errors

### write

ServerResponse.StreamBuilder write(Object object, @Nullable org.springframework.http.MediaType mediaType) throws IOException
Write the given object to the response stream, without flushing. Strings will be sent as UTF-8 encoded bytes, byte arrays will be sent as-is, and other objects will be converted into JSON using message converters.

Parameters:
  `object` - the object to send as data
  `mediaType` - the media type to use for encoding the provided data
Returns:
  this builder
Throws:
  `IOException` - in case of I/O errors

### flush

void flush() throws IOException
Flush the buffered response stream content to the network.

Throws:
  `IOException` - in case of I/O errors