Add basic support for Java 7 NIO file systems (#20293)
This commit is contained in:
parent
6d399a308e
commit
b983f19c1f
23 changed files with 286 additions and 124 deletions
|
|
@ -3,9 +3,8 @@
|
|||
*/
|
||||
package akka.stream.impl.io
|
||||
|
||||
import java.io.File
|
||||
import java.nio.channels.FileChannel
|
||||
import java.nio.file.StandardOpenOption
|
||||
import java.nio.file.{ Path, StandardOpenOption }
|
||||
|
||||
import akka.Done
|
||||
import akka.actor.{ Deploy, ActorLogging, Props }
|
||||
|
|
@ -19,14 +18,14 @@ import scala.util.{ Failure, Success }
|
|||
|
||||
/** INTERNAL API */
|
||||
private[akka] object FileSubscriber {
|
||||
def props(f: File, completionPromise: Promise[IOResult], bufSize: Int, openOptions: Set[StandardOpenOption]) = {
|
||||
def props(f: Path, completionPromise: Promise[IOResult], bufSize: Int, openOptions: Set[StandardOpenOption]) = {
|
||||
require(bufSize > 0, "buffer size must be > 0")
|
||||
Props(classOf[FileSubscriber], f, completionPromise, bufSize, openOptions).withDeploy(Deploy.local)
|
||||
}
|
||||
}
|
||||
|
||||
/** INTERNAL API */
|
||||
private[akka] class FileSubscriber(f: File, completionPromise: Promise[IOResult], bufSize: Int, openOptions: Set[StandardOpenOption])
|
||||
private[akka] class FileSubscriber(f: Path, completionPromise: Promise[IOResult], bufSize: Int, openOptions: Set[StandardOpenOption])
|
||||
extends akka.stream.actor.ActorSubscriber
|
||||
with ActorLogging {
|
||||
|
||||
|
|
@ -37,7 +36,7 @@ private[akka] class FileSubscriber(f: File, completionPromise: Promise[IOResult]
|
|||
private var bytesWritten: Long = 0
|
||||
|
||||
override def preStart(): Unit = try {
|
||||
chan = FileChannel.open(f.toPath, openOptions.asJava)
|
||||
chan = FileChannel.open(f, openOptions.asJava)
|
||||
|
||||
super.preStart()
|
||||
} catch {
|
||||
|
|
@ -57,7 +56,7 @@ private[akka] class FileSubscriber(f: File, completionPromise: Promise[IOResult]
|
|||
}
|
||||
|
||||
case ActorSubscriberMessage.OnError(ex) ⇒
|
||||
log.error(ex, "Tearing down FileSink({}) due to upstream error", f.getAbsolutePath)
|
||||
log.error(ex, "Tearing down FileSink({}) due to upstream error", f)
|
||||
closeAndComplete(IOResult(bytesWritten, Failure(ex)))
|
||||
context.stop(self)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue