Class EntityStreamingSupport
- java.lang.Object
-
- akka.http.javadsl.common.EntityStreamingSupport
-
- akka.http.scaladsl.common.EntityStreamingSupport
-
- Direct Known Subclasses:
CsvEntityStreamingSupport,JsonEntityStreamingSupport
public abstract class EntityStreamingSupport extends EntityStreamingSupport
Entity streaming support trait allowing rendering and receiving incomingSource[T, _]from HTTP entities.See
JsonEntityStreamingSupportorCsvEntityStreamingSupportfor default implementations.
-
-
Constructor Summary
Constructors Constructor Description EntityStreamingSupport()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ContentTypecontentType()Write-side, defines what Content-Type the Marshaller should offer and the final Content-Type of the response.static CsvEntityStreamingSupportcsv()Defaulttext/csv(UTF-8)entity streaming support.static CsvEntityStreamingSupportcsv(int maxLineLength)Defaulttext/csv(UTF-8)entity streaming support.abstract akka.stream.scaladsl.Flow<akka.util.ByteString,akka.util.ByteString,akka.NotUsed>framingDecoder()Read-side, decode incoming framed entity.abstract akka.stream.scaladsl.Flow<akka.util.ByteString,akka.util.ByteString,akka.NotUsed>framingRenderer()Write-side, apply framing to outgoing entity stream.akka.stream.javadsl.Flow<akka.util.ByteString,akka.util.ByteString,akka.NotUsed>getFramingDecoder()Read-side, decode incoming framed entity.akka.stream.javadsl.Flow<akka.util.ByteString,akka.util.ByteString,akka.NotUsed>getFramingRenderer()Write-side, apply framing to outgoing entity stream.static JsonEntityStreamingSupportjson()Defaultapplication/jsonentity streaming support.static JsonEntityStreamingSupportjson(int maxObjectLength)Defaultapplication/jsonentity streaming support.abstract intparallelism()Write-side / read-side, defines if (un)marshalling should be done in parallel.abstract ContentTypeRangesupported()Read-side, what content types it is able to frame and unmarshall.abstract booleanunordered()Write-side / read-side, defines if (un)marshalling should preserve ordering of incoming stream elements.abstract EntityStreamingSupportwithContentType(ContentType range)Write-side, defines what Content-Type the Marshaller should offer and the final Content-Type of the response.abstract EntityStreamingSupportwithParallelMarshalling(int parallelism, boolean unordered)Write-side / read-side, defines parallelism and if ordering should be preserved or not of Source element marshalling.abstract EntityStreamingSupportwithSupported(ContentTypeRange range)Read-side, allows changing what content types are accepted by this framing.
-
-
-
Method Detail
-
json
public static JsonEntityStreamingSupport json()
Defaultapplication/jsonentity streaming support.Provides framing (based on scanning the incoming dataBytes for valid JSON objects, so for example uploads using arrays or new-line separated JSON objects are all parsed correctly) and rendering of Sources as JSON Arrays. A different very popular style of returning streaming JSON is to separate JSON objects on a line-by-line basis, you can configure the support trait to do so by calling
withFramingRendererFlow.Limits the maximum JSON object length to 8KB, if you want to increase this limit provide a value explicitly.
- Returns:
- (undocumented)
-
json
public static JsonEntityStreamingSupport json(int maxObjectLength)
Defaultapplication/jsonentity streaming support.Provides framing (based on scanning the incoming dataBytes for valid JSON objects, so for example uploads using arrays or new-line separated JSON objects are all parsed correctly) and rendering of Sources as JSON Arrays. A different very popular style of returning streaming JSON is to separate JSON objects on a line-by-line basis, you can configure the support trait to do so by calling
withFramingRendererFlow.- Parameters:
maxObjectLength- (undocumented)- Returns:
- (undocumented)
-
csv
public static CsvEntityStreamingSupport csv()
Defaulttext/csv(UTF-8)entity streaming support. Provides framing and rendering of\nseparated lines and marshalling Sources into such values.Limits the maximum line-length to 8KB, if you want to increase this limit provide a value explicitly.
- Returns:
- (undocumented)
-
csv
public static CsvEntityStreamingSupport csv(int maxLineLength)
Defaulttext/csv(UTF-8)entity streaming support. Provides framing and rendering of\nseparated lines and marshalling Sources into such values.- Parameters:
maxLineLength- (undocumented)- Returns:
- (undocumented)
-
supported
public abstract ContentTypeRange supported()
Read-side, what content types it is able to frame and unmarshall.- Specified by:
supportedin classEntityStreamingSupport
-
contentType
public abstract ContentType contentType()
Write-side, defines what Content-Type the Marshaller should offer and the final Content-Type of the response.- Specified by:
contentTypein classEntityStreamingSupport
-
framingDecoder
public abstract akka.stream.scaladsl.Flow<akka.util.ByteString,akka.util.ByteString,akka.NotUsed> framingDecoder()
Read-side, decode incoming framed entity. For example with an incoming JSON array, chunk it up into JSON objects contained within that array.- Returns:
- (undocumented)
-
getFramingDecoder
public final akka.stream.javadsl.Flow<akka.util.ByteString,akka.util.ByteString,akka.NotUsed> getFramingDecoder()
Description copied from class:EntityStreamingSupportRead-side, decode incoming framed entity. For example with an incoming JSON array, chunk it up into JSON objects contained within that array.- Specified by:
getFramingDecoderin classEntityStreamingSupport- Returns:
- (undocumented)
-
framingRenderer
public abstract akka.stream.scaladsl.Flow<akka.util.ByteString,akka.util.ByteString,akka.NotUsed> framingRenderer()
Write-side, apply framing to outgoing entity stream.Most typical usage will be a variant of
Flow[ByteString].intersperse.For example for rendering a JSON array one would return
Flow[ByteString].intersperse(ByteString("["), ByteString(","), ByteString("]"))and for rendering a new-line separated CSV simplyFlow[ByteString].intersperse(ByteString("\n")).- Returns:
- (undocumented)
-
getFramingRenderer
public final akka.stream.javadsl.Flow<akka.util.ByteString,akka.util.ByteString,akka.NotUsed> getFramingRenderer()
Description copied from class:EntityStreamingSupportWrite-side, apply framing to outgoing entity stream.Most typical usage will be a variant of
Flow[ByteString].intersperse.For example for rendering a JSON array one would return
Flow[ByteString].intersperse(ByteString("["), ByteString(","), ByteString("]"))and for rendering a new-line separated CSV simplyFlow[ByteString].intersperse(ByteString("\n")).- Specified by:
getFramingRendererin classEntityStreamingSupport- Returns:
- (undocumented)
-
withSupported
public abstract EntityStreamingSupport withSupported(ContentTypeRange range)
Read-side, allows changing what content types are accepted by this framing.EntityStreamingSupport traits MUST support re-configuring the accepted
ContentTypeRange.This is in order to support a-typical APIs which users still want to communicate with using the provided support trait. Typical examples include APIs which return valid
application/jsonhowever advertise the content type as beingapplication/javascriptor vendor specific content types, which still parse correctly as JSON, CSV or something else that a provided support trait is built for.NOTE: Implementations should specialize the return type to their own Type!
- Specified by:
withSupportedin classEntityStreamingSupport- Parameters:
range- (undocumented)- Returns:
- (undocumented)
-
withContentType
public abstract EntityStreamingSupport withContentType(ContentType range)
Write-side, defines what Content-Type the Marshaller should offer and the final Content-Type of the response.EntityStreamingSupport traits MUST support re-configuring the offered
ContentType. This is due to the need integrating with existing systems which sometimes expect custom Content-Types, however really are just plain JSON or something else internally (perhaps with slight extensions).NOTE: Implementations should specialize the return type to their own Type!
- Specified by:
withContentTypein classEntityStreamingSupport- Parameters:
range- (undocumented)- Returns:
- (undocumented)
-
parallelism
public abstract int parallelism()
Write-side / read-side, defines if (un)marshalling should be done in parallel.This may be beneficial marshalling the bottleneck in the pipeline.
See also
parallelism()andwithParallelMarshalling(int,boolean).- Specified by:
parallelismin classEntityStreamingSupport- Returns:
- (undocumented)
-
unordered
public abstract boolean unordered()
Write-side / read-side, defines if (un)marshalling should preserve ordering of incoming stream elements.Allowing for parallel and unordered (un)marshalling often yields higher throughput and also allows avoiding head-of-line blocking if some elements are much larger than others.
See also
parallelism()andwithParallelMarshalling(int,boolean).- Specified by:
unorderedin classEntityStreamingSupport- Returns:
- (undocumented)
-
withParallelMarshalling
public abstract EntityStreamingSupport withParallelMarshalling(int parallelism, boolean unordered)
Write-side / read-side, defines parallelism and if ordering should be preserved or not of Source element marshalling.Sometimes marshalling multiple elements at once (esp. when elements are not evenly sized, and ordering is not enforced) may yield in higher throughput.
NOTE: Implementations should specialize the return type to their own Type!
- Specified by:
withParallelMarshallingin classEntityStreamingSupport- Parameters:
parallelism- (undocumented)unordered- (undocumented)- Returns:
- (undocumented)
-
-