public final class Streams extends Object
StreamConverter with Riptide
(using streamConverter()) and declare a route for your stream that is calling a the stream consumer
as follows:
try (Rest rest = Rest.builder().baseUrl("https://api.github.com").converter(streamConverter()).build()) {
rest.get("/repos/{org}/{repo}/contributors", "zalando", "riptide")
.accept(MediaType.APPLICATION_JSON)
.dispatch(series(),
on(SUCCESSFUL).call(streamOf(User.class),
forEach(user -> println(user.login + " (" + user.contributions + ")"))))
.get();
}
Note: The stream converter is an replacement to the default spring JSON converter that does not support
streaming, and thus should be not registered together with it.| Modifier and Type | Field and Description |
|---|---|
static org.springframework.http.MediaType |
APPLICATION_JSON_SEQ
Default singleton
media type for application/json-seq. |
static org.springframework.http.MediaType |
APPLICATION_X_JSON_STREAM
Default singleton
media type for application/x-json-stream. |
| Constructor and Description |
|---|
Streams() |
| Modifier and Type | Method and Description |
|---|---|
static <I,X extends Throwable> |
forEach(org.zalando.fauxpas.ThrowingConsumer<I,X> consumer)
Creates
stream consumer for given element consumer. |
static org.springframework.http.converter.HttpMessageConverter<?> |
streamConverter()
Create default stream converter.
|
static org.springframework.http.converter.HttpMessageConverter<?> |
streamConverter(com.fasterxml.jackson.databind.ObjectMapper mapper)
Create stream converter with custom {@link ObjectMapper object mapper).
|
static org.springframework.http.converter.HttpMessageConverter<?> |
streamConverter(com.fasterxml.jackson.databind.ObjectMapper mapper,
List<org.springframework.http.MediaType> medias)
Create stream converter with custom ObjectMapper object mapper), and custom list of {@link MediaType media
types}.
|
static <T> com.google.common.reflect.TypeToken<Stream<T>> |
streamOf(Class<T> type)
Creates specialized stream
type token for the given element class type. |
static <T> com.google.common.reflect.TypeToken<Stream<T>> |
streamOf(com.google.common.reflect.TypeToken<T> type)
Creates specialized stream
type token for the given element type token. |
public static final org.springframework.http.MediaType APPLICATION_X_JSON_STREAM
media type for application/x-json-stream.public static final org.springframework.http.MediaType APPLICATION_JSON_SEQ
media type for application/json-seq.public static <T> com.google.common.reflect.TypeToken<Stream<T>> streamOf(Class<T> type)
type token for the given element class type. Used to
declare the expected stream response type token in Riptide route as follows:
on(...).call(streamOf(Result.class),...)
type - element class type.public static <T> com.google.common.reflect.TypeToken<Stream<T>> streamOf(com.google.common.reflect.TypeToken<T> type)
type token for the given element type token. Used
to declare the expected stream response type token in Riptide route as follows:
on(...).call(streamOf(resultTypeToken),...)
type - element token type.public static <I,X extends Throwable> org.zalando.fauxpas.ThrowingConsumer<Stream<I>,X> forEach(org.zalando.fauxpas.ThrowingConsumer<I,X> consumer)
stream consumer for given element consumer. Used to
standardly wrap a single entity consumer function in a stream consumer function as follows:
on(...).call(streamOf(...), forEach(element -> { println(element); }))
consumer - element consumer function.public static org.springframework.http.converter.HttpMessageConverter<?> streamConverter()
public static org.springframework.http.converter.HttpMessageConverter<?> streamConverter(com.fasterxml.jackson.databind.ObjectMapper mapper)
mapper - custom object mapper.public static org.springframework.http.converter.HttpMessageConverter<?> streamConverter(com.fasterxml.jackson.databind.ObjectMapper mapper,
List<org.springframework.http.MediaType> medias)
mapper - custom object mapper.medias - custom list of media types.Copyright © 2015–2017 Zalando SE. All rights reserved.