!str #19129 New homes for file and java.io stream factories
This commit is contained in:
parent
5041d3825d
commit
09a79f45e4
31 changed files with 420 additions and 327 deletions
|
|
@ -245,34 +245,34 @@ class MigrationsScala extends AkkaSpec {
|
|||
//#query-param
|
||||
|
||||
//#file-source-sink
|
||||
val fileSrc = Source.file(new File("."))
|
||||
val fileSrc = FileIO.fromFile(new File("."))
|
||||
|
||||
val otherFileSrc = Source.file(new File("."), 1024)
|
||||
val otherFileSrc = FileIO.fromFile(new File("."), 1024)
|
||||
|
||||
val someFileSink = Sink.file(new File("."))
|
||||
val someFileSink = FileIO.toFile(new File("."))
|
||||
//#file-source-sink
|
||||
|
||||
class SomeInputStream extends java.io.InputStream { override def read(): Int = 0 }
|
||||
class SomeOutputStream extends java.io.OutputStream { override def write(b: Int): Unit = () }
|
||||
|
||||
//#input-output-stream-source-sink
|
||||
val inputStreamSrc = Source.inputStream(() => new SomeInputStream())
|
||||
val inputStreamSrc = StreamConverters.fromInputStream(() => new SomeInputStream())
|
||||
|
||||
val otherInputStreamSrc = Source.inputStream(() => new SomeInputStream())
|
||||
val otherInputStreamSrc = StreamConverters.fromInputStream(() => new SomeInputStream())
|
||||
|
||||
val someOutputStreamSink = Sink.outputStream(() => new SomeOutputStream())
|
||||
val someOutputStreamSink = StreamConverters.fromOutputStream(() => new SomeOutputStream())
|
||||
//#input-output-stream-source-sink
|
||||
|
||||
//#output-input-stream-source-sink
|
||||
val timeout: FiniteDuration = 0.seconds
|
||||
|
||||
val outputStreamSrc = Source.outputStream()
|
||||
val outputStreamSrc = StreamConverters.asOutputStream()
|
||||
|
||||
val otherOutputStreamSrc = Source.outputStream(timeout)
|
||||
val otherOutputStreamSrc = StreamConverters.asOutputStream(timeout)
|
||||
|
||||
val someInputStreamSink = Sink.inputStream()
|
||||
val someInputStreamSink = StreamConverters.asInputStream()
|
||||
|
||||
val someOtherInputStreamSink = Sink.inputStream(timeout)
|
||||
val someOtherInputStreamSink = StreamConverters.asInputStream(timeout)
|
||||
//#output-input-stream-source-sink
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class FileUploadExamplesSpec extends RoutingSpec {
|
|||
// stream into a file as the chunks of it arrives and return a future
|
||||
// file to where it got stored
|
||||
val file = File.createTempFile("upload", "tmp")
|
||||
b.entity.dataBytes.runWith(Sink.file(file)).map(_ =>
|
||||
b.entity.dataBytes.runWith(FileIO.toFile(file)).map(_ =>
|
||||
(b.name -> file))
|
||||
|
||||
case b: BodyPart =>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import akka.http.scaladsl.model.headers.{ Server, RawHeader }
|
|||
import akka.http.scaladsl.server.RouteResult.{ Complete, Rejected }
|
||||
import akka.http.scaladsl.server._
|
||||
import akka.stream.ActorMaterializer
|
||||
import akka.stream.scaladsl.{ Sink, Source }
|
||||
import akka.stream.scaladsl.{FileIO, Sink, Source}
|
||||
import akka.util.ByteString
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
|
@ -174,7 +174,7 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
|||
path("sample") {
|
||||
complete {
|
||||
// internally uses the configured fileIODispatcher:
|
||||
val source = Source.file(new File("example.json"))
|
||||
val source = FileIO.fromFile(new File("example.json"))
|
||||
HttpResponse(entity = HttpEntity(ContentTypes.`application/json`, source))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ package docs.stream.io
|
|||
import java.io.File
|
||||
|
||||
import akka.stream._
|
||||
import akka.stream.scaladsl.Sink
|
||||
import akka.stream.scaladsl.Source
|
||||
import akka.stream.scaladsl.{ FileIO, Sink, Source }
|
||||
import akka.stream.testkit.Utils._
|
||||
import akka.stream.testkit._
|
||||
import akka.util.ByteString
|
||||
|
|
@ -46,7 +45,7 @@ class StreamFileDocSpec extends AkkaSpec(UnboundedMailboxConfig) {
|
|||
|
||||
//#file-source
|
||||
|
||||
val foreach: Future[Long] = Source.file(file)
|
||||
val foreach: Future[Long] = FileIO.fromFile(file)
|
||||
.to(Sink.ignore)
|
||||
.run()
|
||||
//#file-source
|
||||
|
|
@ -54,7 +53,7 @@ class StreamFileDocSpec extends AkkaSpec(UnboundedMailboxConfig) {
|
|||
|
||||
"configure dispatcher in code" in {
|
||||
//#custom-dispatcher-code
|
||||
Sink.file(file)
|
||||
FileIO.fromFile(file)
|
||||
.withAttributes(ActorAttributes.dispatcher("custom-blocking-io-dispatcher"))
|
||||
//#custom-dispatcher-code
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue