Add basic support for Java 7 NIO file systems (#20293)

This commit is contained in:
Michał Kiędyś 2016-04-25 19:25:26 +10:00 committed by Konrad Malawski
parent 6d399a308e
commit b983f19c1f
23 changed files with 286 additions and 124 deletions

View file

@ -4,7 +4,7 @@
package docs.http.scaladsl.server.directives
import java.io.File
import java.nio.file.Paths
import akka.actor.ActorSystem
import akka.event.Logging
@ -190,7 +190,7 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
path("sample") {
complete {
// internally uses the configured fileIODispatcher:
val source = FileIO.fromFile(new File("example.json"))
val source = FileIO.fromPath(Paths.get("example.json"))
HttpResponse(entity = HttpEntity(ContentTypes.`application/json`, source))
}
}

View file

@ -15,7 +15,7 @@ import org.scalatest._
import org.scalatest.concurrent._
import scala.concurrent._
import scala.concurrent.duration._
import java.io.File
import java.nio.file.Paths
class QuickStartDocSpec extends WordSpec with BeforeAndAfterAll with ScalaFutures {
implicit val patience = PatienceConfig(5.seconds)
@ -46,7 +46,7 @@ class QuickStartDocSpec extends WordSpec with BeforeAndAfterAll with ScalaFuture
val result: Future[IOResult] =
factorials
.map(num => ByteString(s"$num\n"))
.runWith(FileIO.toFile(new File("factorials.txt")))
.runWith(FileIO.toPath(Paths.get("factorials.txt")))
//#transform-source
//#use-transformed-sink
@ -71,7 +71,7 @@ class QuickStartDocSpec extends WordSpec with BeforeAndAfterAll with ScalaFuture
def lineSink(filename: String): Sink[String, Future[IOResult]] =
Flow[String]
.map(s => ByteString(s + "\n"))
.toMat(FileIO.toFile(new File(filename)))(Keep.right)
.toMat(FileIO.toPath(Paths.get(filename)))(Keep.right)
//#transform-sink
}

View file

@ -31,9 +31,11 @@ object TwitterStreamQuickstartDocSpec {
val akka = Hashtag("#akka")
//#model
// format: OFF
//#tweet-source
val tweets: Source[Tweet, NotUsed]
//#tweet-source
// format: ON
= Source(
Tweet(Author("rolandkuhn"), System.currentTimeMillis, "#akka rocks!") ::
Tweet(Author("patriknw"), System.currentTimeMillis, "#akka !") ::

View file

@ -3,10 +3,10 @@
*/
package docs.stream.io
import java.io.File
import java.nio.file.{ Files, Paths }
import akka.stream._
import akka.stream.scaladsl.{ FileIO, Sink, Source }
import akka.stream.scaladsl.{ FileIO, Sink }
import akka.stream.testkit.Utils._
import akka.stream.testkit._
import akka.util.ByteString
@ -22,9 +22,9 @@ class StreamFileDocSpec extends AkkaSpec(UnboundedMailboxConfig) {
// silence sysout
def println(s: String) = ()
val file = File.createTempFile(getClass.getName, ".tmp")
val file = Files.createTempFile(getClass.getName, ".tmp")
override def afterTermination() = file.delete()
override def afterTermination() = Files.delete(file)
{
//#file-source
@ -35,7 +35,7 @@ class StreamFileDocSpec extends AkkaSpec(UnboundedMailboxConfig) {
{
//#file-source
val file = new File("example.csv")
val file = Paths.get("example.csv")
//#file-source
}
@ -46,7 +46,7 @@ class StreamFileDocSpec extends AkkaSpec(UnboundedMailboxConfig) {
//#file-source
val foreach: Future[IOResult] = FileIO.fromFile(file)
val foreach: Future[IOResult] = FileIO.fromPath(file)
.to(Sink.ignore)
.run()
//#file-source
@ -54,7 +54,7 @@ class StreamFileDocSpec extends AkkaSpec(UnboundedMailboxConfig) {
"configure dispatcher in code" in {
//#custom-dispatcher-code
FileIO.fromFile(file)
FileIO.fromPath(file)
.withAttributes(ActorAttributes.dispatcher("custom-blocking-io-dispatcher"))
//#custom-dispatcher-code
}