Merge pull request #17948 from spray/w/small-java-api-additions

Smallish Java API fixes
This commit is contained in:
drewhk 2015-07-09 14:44:05 +02:00
commit 76eef58411
6 changed files with 54 additions and 3 deletions

View file

@ -4,6 +4,8 @@
package akka.http.javadsl.model;
import akka.http.impl.util.Util;
import akka.http.scaladsl.model.HttpEntity;
import akka.util.ByteString;
/**
@ -31,4 +33,30 @@ public abstract class ChunkStreamPart {
* it will be empty.
*/
public abstract Iterable<HttpHeader> getTrailerHeaders();
/**
* Creates a chunk from data and extension.
*/
public static ChunkStreamPart create(ByteString data, String extension) {
return new HttpEntity.Chunk(data, extension);
}
/**
* Creates a chunk from data with an empty extension.
*/
public static ChunkStreamPart create(ByteString data) {
return create(data, "");
}
/**
* The default last ChunkStreamPart that has no extension and no trailer headers.
*/
public static final ChunkStreamPart LAST = HttpEntity.LastChunk$.MODULE$;
/**
* Creates a last chunk with extension and headers.
*/
public static ChunkStreamPart createLast(String extension, Iterable<HttpHeader> trailerHeaders){
return new HttpEntity.LastChunk(extension, Util.<HttpHeader, akka.http.scaladsl.model.HttpHeader>convertIterable(trailerHeaders));
}
}

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

@ -10,6 +10,6 @@ package akka.http.javadsl.model;
public final class HttpProtocols {
private HttpProtocols() {}
final HttpProtocol HTTP_1_0 = akka.http.scaladsl.model.HttpProtocols.HTTP$div1$u002E0();
final HttpProtocol HTTP_1_1 = akka.http.scaladsl.model.HttpProtocols.HTTP$div1$u002E1();
public final static HttpProtocol HTTP_1_0 = akka.http.scaladsl.model.HttpProtocols.HTTP$div1$u002E0();
public final static HttpProtocol HTTP_1_1 = akka.http.scaladsl.model.HttpProtocols.HTTP$div1$u002E1();
}

View file

@ -16,4 +16,7 @@ public abstract class Location extends akka.http.scaladsl.model.HttpHeader {
public static Location create(Uri uri) {
return new akka.http.scaladsl.model.headers.Location(akka.http.impl.util.Util.convertUriToScala(uri));
}
public static Location create(String uri) {
return create(Uri.create(uri));
}
}

View file

@ -5,6 +5,7 @@
package akka.http.javadsl
import java.net.InetSocketAddress
import akka.japi.function.Function;
import scala.concurrent.Future
import akka.stream.Materializer
import akka.stream.javadsl.Flow

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 */