+htc #18250 add HttpEntity#apply(contentType, source) for Chunked

This commit is contained in:
Konrad Malawski 2015-08-18 18:25:05 +02:00
parent 0c6ed6d83d
commit 9053259fe4
2 changed files with 9 additions and 1 deletions

View file

@ -7,9 +7,10 @@ package akka.http.javadsl.model;
import java.io.File;
import akka.http.impl.util.JavaAccessors;
import akka.http.scaladsl.model.*;
import akka.http.scaladsl.model.HttpEntity;
import akka.util.ByteString;
import akka.stream.javadsl.Source;
import akka.http.scaladsl.model.HttpEntity$;
/** Constructors for HttpEntity instances */
public final class HttpEntities {
@ -51,6 +52,10 @@ public final class HttpEntities {
return new akka.http.scaladsl.model.HttpEntity.Default((akka.http.scaladsl.model.ContentType) contentType, contentLength, data.asScala());
}
public static HttpEntity.Chunked create(ContentType contentType, Source<ByteString, Object> data) {
return HttpEntity.Chunked$.MODULE$.fromData((akka.http.scaladsl.model.ContentType) contentType, data.asScala());
}
public static HttpEntityCloseDelimited createCloseDelimited(ContentType contentType, Source<ByteString, Object> data) {
return new akka.http.scaladsl.model.HttpEntity.CloseDelimited((akka.http.scaladsl.model.ContentType) contentType, data.asScala());
}

View file

@ -160,8 +160,11 @@ object HttpEntity {
if (bytes.length == 0) empty(contentType) else apply(contentType, ByteString(bytes))
def apply(contentType: ContentType, data: ByteString): Strict =
if (data.isEmpty) empty(contentType) else Strict(contentType, data)
def apply(contentType: ContentType, contentLength: Long, data: Source[ByteString, Any]): UniversalEntity =
if (contentLength == 0) empty(contentType) else Default(contentType, contentLength, data)
def apply(contentType: ContentType, data: Source[ByteString, Any]): Chunked =
Chunked.fromData(contentType, data)
def apply(contentType: ContentType, file: File, chunkSize: Int = SynchronousFileSource.DefaultChunkSize): UniversalEntity = {
val fileLength = file.length