!str - 18916 - Source.file and Sink.file
* Removes `Synchronous` from the names and descriptions of File I/O as it leaks impl details * Removes the factries for FileSource and FileSink and puts them in Source and Sink respectively
This commit is contained in:
parent
7d4304fc6e
commit
20c996fe41
31 changed files with 262 additions and 242 deletions
|
|
@ -12,7 +12,6 @@ import scala.concurrent.duration._
|
|||
import scala.collection.immutable
|
||||
import akka.util.ByteString
|
||||
import akka.stream.scaladsl._
|
||||
import akka.stream.io.SynchronousFileSource
|
||||
import akka.stream.stage._
|
||||
import akka.stream._
|
||||
import akka.{ japi, stream }
|
||||
|
|
@ -120,8 +119,8 @@ sealed trait BodyPartEntity extends HttpEntity with jm.BodyPartEntity {
|
|||
def withContentType(contentType: ContentType): BodyPartEntity
|
||||
|
||||
/**
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
def withSizeLimit(maxBytes: Long): BodyPartEntity
|
||||
}
|
||||
|
||||
|
|
@ -134,8 +133,8 @@ sealed trait RequestEntity extends HttpEntity with jm.RequestEntity with Respons
|
|||
def withContentType(contentType: ContentType): RequestEntity
|
||||
|
||||
/**
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
def withSizeLimit(maxBytes: Long): RequestEntity
|
||||
|
||||
def transformDataBytes(transformer: Flow[ByteString, ByteString, Any]): RequestEntity
|
||||
|
|
@ -150,8 +149,8 @@ sealed trait ResponseEntity extends HttpEntity with jm.ResponseEntity {
|
|||
def withContentType(contentType: ContentType): ResponseEntity
|
||||
|
||||
/**
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
def withSizeLimit(maxBytes: Long): ResponseEntity
|
||||
|
||||
def transformDataBytes(transformer: Flow[ByteString, ByteString, Any]): ResponseEntity
|
||||
|
|
@ -161,8 +160,8 @@ sealed trait UniversalEntity extends jm.UniversalEntity with MessageEntity with
|
|||
def withContentType(contentType: ContentType): UniversalEntity
|
||||
|
||||
/**
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
def withSizeLimit(maxBytes: Long): UniversalEntity
|
||||
|
||||
def contentLength: Long
|
||||
|
|
@ -195,7 +194,7 @@ object HttpEntity {
|
|||
val fileLength = file.length
|
||||
if (fileLength > 0)
|
||||
Default(contentType, fileLength,
|
||||
if (chunkSize > 0) SynchronousFileSource(file, chunkSize) else SynchronousFileSource(file))
|
||||
if (chunkSize > 0) Source.file(file, chunkSize) else Source.file(file))
|
||||
else empty(contentType)
|
||||
}
|
||||
|
||||
|
|
@ -233,8 +232,8 @@ object HttpEntity {
|
|||
if (contentType == this.contentType) this else copy(contentType = contentType)
|
||||
|
||||
/**
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
def withSizeLimit(maxBytes: Long): UniversalEntity =
|
||||
if (data.length <= maxBytes) this
|
||||
else Default(contentType, data.length, limitableByteSource(Source.single(data))) withSizeLimit maxBytes
|
||||
|
|
@ -265,8 +264,8 @@ object HttpEntity {
|
|||
if (contentType == this.contentType) this else copy(contentType = contentType)
|
||||
|
||||
/**
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
def withSizeLimit(maxBytes: Long): Default =
|
||||
copy(data = data withAttributes Attributes(SizeLimit(maxBytes, Some(contentLength))))
|
||||
|
||||
|
|
@ -287,8 +286,8 @@ object HttpEntity {
|
|||
def dataBytes: Source[ByteString, Any] = data
|
||||
|
||||
/**
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
* See [[HttpEntity#withSizeLimit]].
|
||||
*/
|
||||
def withSizeLimit(maxBytes: Long): Self =
|
||||
withData(data withAttributes Attributes(SizeLimit(maxBytes)))
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import scala.concurrent.{ Future, ExecutionContext }
|
|||
import scala.collection.immutable
|
||||
import scala.util.{ Failure, Success, Try }
|
||||
import akka.stream.Materializer
|
||||
import akka.stream.io.SynchronousFileSource
|
||||
import akka.stream.scaladsl.{ Source }
|
||||
import akka.http.scaladsl.util.FastFuture
|
||||
import akka.http.scaladsl.model.headers._
|
||||
|
|
@ -236,7 +235,7 @@ object Multipart {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a BodyPart backed by a File that will be streamed using a SynchronousFileSource.
|
||||
* Creates a BodyPart backed by a File that will be streamed using a FileSource.
|
||||
*/
|
||||
def fromFile(name: String, contentType: ContentType, file: File, chunkSize: Int = -1): BodyPart =
|
||||
BodyPart(name, HttpEntity(contentType, file, chunkSize), Map("filename" -> file.getName))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue