+htc add javadsl.model.HttpEntity.toStrict

This commit is contained in:
Johannes Rudolph 2015-07-08 14:40:40 +02:00
parent da485055a3
commit b7d5805e9b
2 changed files with 20 additions and 1 deletions

View file

@ -6,8 +6,10 @@ package akka.http.javadsl.model;
import akka.http.scaladsl.model.HttpEntity$;
import akka.japi.Option;
import akka.stream.Materializer;
import akka.stream.javadsl.Source;
import akka.util.ByteString;
import scala.concurrent.Future;
/**
* Represents the entity of an Http message. An entity consists of the content-type of the data
@ -80,4 +82,15 @@ public interface HttpEntity {
* Returns a stream of data bytes this entity consists of.
*/
public abstract Source<ByteString, ?> getDataBytes();
/**
* Returns a future of a strict entity that contains the same data as this entity
* which is only completed when the complete entity has been collected. As the
* duration of receiving the complete entity cannot be predicted, a timeout needs to
* be specified to guard the process against running and keeping resources infinitely.
*
* Use getDataBytes and stream processing instead if the expected data is big or
* is likely to take a long time.
*/
public abstract Future<HttpEntityStrict> toStrict(long timeoutMillis, Materializer materializer);
}

View file

@ -4,11 +4,13 @@
package akka.http.scaladsl.model
import akka.http.javadsl.model.HttpEntityStrict
import language.implicitConversions
import java.io.File
import java.lang.{ Iterable JIterable, Long JLong }
import scala.concurrent.Future
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.duration._
import scala.collection.immutable
import akka.util.ByteString
import akka.stream.Materializer
@ -103,6 +105,10 @@ sealed trait HttpEntity extends jm.HttpEntity {
def isIndefiniteLength: Boolean = false
def isDefault: Boolean = false
def isChunked: Boolean = false
/** Java API */
def toStrict(timeoutMillis: Long, materializer: Materializer): Future[HttpEntityStrict] =
toStrict(timeoutMillis.millis)(materializer)
}
/* An entity that can be used for body parts */