+str #15588,#17229 Java 6 Synchronous File Sink / Source
These are synchronous implementations, because we need to be Java 6 compatible while developing on 2.3.x. However asynchronous implementations using AsynchronousFileChannel will come soon for JDK7 users. + ActorPublisher/Subscriber now manage stopping of the actor + added documentation on configuring dispatcher for File IO + properly handle if source file does not exist + file sink / source come with default io dispatcher > verified no actors are leaking > exceptions are caught and onErrored properly + moved files to akka.stream.io + Added OutputStreamSink and InputStreamSource
This commit is contained in:
parent
a1639c4312
commit
cebd9bf1ae
37 changed files with 1581 additions and 86 deletions
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package docs.stream.io
|
||||
|
||||
import java.io.File
|
||||
|
||||
import akka.stream._
|
||||
import akka.stream.io.SynchronousFileSource
|
||||
import akka.stream.io.SynchronousFileSink
|
||||
import akka.stream.testkit.AkkaSpec
|
||||
import akka.stream.testkit.StreamTestKit
|
||||
import akka.util.ByteString
|
||||
|
||||
class StreamFileDocSpec extends AkkaSpec(StreamTestKit.UnboundedMailboxConfig) {
|
||||
|
||||
implicit val ec = system.dispatcher
|
||||
implicit val mat = ActorFlowMaterializer()
|
||||
|
||||
// silence sysout
|
||||
def println(s: String) = ()
|
||||
|
||||
val file = File.createTempFile(getClass.getName, ".tmp")
|
||||
|
||||
override def afterTermination() = file.delete()
|
||||
|
||||
{
|
||||
//#file-source
|
||||
import akka.stream.io._
|
||||
//#file-source
|
||||
}
|
||||
|
||||
{
|
||||
//#file-source
|
||||
val file = new File("example.csv")
|
||||
//#file-source
|
||||
}
|
||||
|
||||
"read data from a file" in {
|
||||
//#file-source
|
||||
def handle(b: ByteString): Unit //#file-source
|
||||
= ()
|
||||
|
||||
//#file-source
|
||||
|
||||
SynchronousFileSource(file)
|
||||
.runForeach((chunk: ByteString) ⇒ handle(chunk))
|
||||
//#file-source
|
||||
}
|
||||
|
||||
"configure dispatcher in code" in {
|
||||
//#custom-dispatcher-code
|
||||
SynchronousFileSink(file)
|
||||
.withAttributes(ActorOperationAttributes.dispatcher("custom-file-io-dispatcher"))
|
||||
//#custom-dispatcher-code
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,22 @@
|
|||
/**
|
||||
* Copyright (C) 2014 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package docs.stream
|
||||
package docs.stream.io
|
||||
|
||||
import java.net.InetSocketAddress
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import akka.actor.ActorSystem
|
||||
|
||||
import akka.stream._
|
||||
import akka.stream.scaladsl.StreamTcp._
|
||||
import akka.stream.scaladsl._
|
||||
import akka.stream.stage.{ PushStage, SyncDirective, Context }
|
||||
import akka.stream.stage.Context
|
||||
import akka.stream.stage.PushStage
|
||||
import akka.stream.stage.SyncDirective
|
||||
import akka.stream.testkit.AkkaSpec
|
||||
import akka.testkit.TestProbe
|
||||
import akka.util.ByteString
|
||||
import cookbook.RecipeParseLines
|
||||
import docs.stream.cookbook.RecipeParseLines
|
||||
import docs.utils.TestUtils
|
||||
import StreamTcp._
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue