Package play.http
Class HttpEntity
- Object
-
- play.http.HttpEntity
-
- Direct Known Subclasses:
HttpEntity.Chunked,HttpEntity.Streamed,HttpEntity.Strict
public abstract class HttpEntity extends Object
An HTTP entity
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpEntity.ChunkedA chunked entity, backed by a source of chunks.static classHttpEntity.StreamedA streamed entity, backed by a source.static classHttpEntity.StrictA strict entity, where all the data for it is in memory.
-
Field Summary
Fields Modifier and Type Field Description static HttpEntityNO_ENTITYNo entity.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract HttpEntityas(String contentType)abstract play.api.http.HttpEntityasScala()static HttpEntitychunked(Source<ByteString,?> data, Optional<String> contentType)Convert the given source of ByteStrings to a chunked entity.CompletionStage<ByteString>consumeData(Materializer mat)Consumes the data.abstract Optional<Long>contentLength()abstract Optional<String>contentType()abstract Source<ByteString,?>dataStream()static HttpEntityfromContent(play.twirl.api.Content content, String charset)Create an entity from the given content.static HttpEntityfromString(String content, String charset)Create an entity from the given String.abstract booleanisKnownEmpty()
-
-
-
Field Detail
-
NO_ENTITY
public static final HttpEntity NO_ENTITY
No entity.
-
-
Method Detail
-
isKnownEmpty
public abstract boolean isKnownEmpty()
- Returns:
- Whether the entity is known to be empty or not.
-
dataStream
public abstract Source<ByteString,?> dataStream()
- Returns:
- The stream of data.
-
as
public abstract HttpEntity as(String contentType)
- Parameters:
contentType- the content type to use, i.e. "text/html".- Returns:
- Return the entity as the given content type.
-
consumeData
public CompletionStage<ByteString> consumeData(Materializer mat)
Consumes the data.This method should be used carefully, since if the source represents an ephemeral stream, then the entity may not be usable after this method is invoked.
- Parameters:
mat- the application's materializer.- Returns:
- a CompletionStage holding the data
-
asScala
public abstract play.api.http.HttpEntity asScala()
-
fromContent
public static final HttpEntity fromContent(play.twirl.api.Content content, String charset)
Create an entity from the given content.- Parameters:
content- The content.charset- The charset.- Returns:
- the HTTP entity.
-
fromString
public static final HttpEntity fromString(String content, String charset)
Create an entity from the given String.- Parameters:
content- The content.charset- The charset.- Returns:
- the HTTP entity.
-
chunked
public static final HttpEntity chunked(Source<ByteString,?> data, Optional<String> contentType)
Convert the given source of ByteStrings to a chunked entity.- Parameters:
data- The source.contentType- The optional content type.- Returns:
- The ByteStrings.
-
-