Class FileIO


  • public class FileIO
    extends java.lang.Object
    Factories to create sinks and sources from files
    • Constructor Summary

      Constructors 
      Constructor Description
      FileIO()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static Source<ByteString,​scala.concurrent.Future<IOResult>> fromFile​(java.io.File f, int chunkSize)
      Deprecated.
      Use `fromPath` instead.
      static int fromFile$default$2()  
      static Source<ByteString,​scala.concurrent.Future<IOResult>> fromPath​(java.nio.file.Path f, int chunkSize)
      Creates a Source from a files contents.
      static Source<ByteString,​scala.concurrent.Future<IOResult>> fromPath​(java.nio.file.Path f, int chunkSize, long startPosition)
      Creates a Source from a files contents.
      static int fromPath$default$2()  
      static Sink<ByteString,​scala.concurrent.Future<IOResult>> toFile​(java.io.File f, scala.collection.immutable.Set<java.nio.file.OpenOption> options)
      Deprecated.
      Use `toPath` instead.
      static scala.collection.immutable.Set<java.nio.file.OpenOption> toFile$default$2()  
      static Sink<ByteString,​scala.concurrent.Future<IOResult>> toPath​(java.nio.file.Path f, scala.collection.immutable.Set<java.nio.file.OpenOption> options)
      Creates a Sink which writes incoming ByteString elements to the given file path.
      static Sink<ByteString,​scala.concurrent.Future<IOResult>> toPath​(java.nio.file.Path f, scala.collection.immutable.Set<java.nio.file.OpenOption> options, long startPosition)
      Creates a Sink which writes incoming ByteString elements to the given file path.
      static scala.collection.immutable.Set<java.nio.file.OpenOption> toPath$default$2()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileIO

        public FileIO()
    • Method Detail

      • fromFile

        public static Source<ByteString,​scala.concurrent.Future<IOResult>> fromFile​(java.io.File f,
                                                                                          int chunkSize)
        Deprecated.
        Use `fromPath` instead. Since 2.4.5.
        Creates a Source from a files contents. Emitted elements are chunkSize sized ByteString elements, except the final element, which will be up to chunkSize in size.

        You can configure the default dispatcher for this Source by changing the akka.stream.materializer.blocking-io-dispatcher or set it for a given Source by using ActorAttributes.

        It materializes a Future of IOResult containing the number of bytes read from the source file upon completion, and a possible exception if IO operation was not completed successfully. Note that bytes having been read by the source does not give any guarantee that the bytes were seen by downstream stages.

        Parameters:
        f - the file to read from
        chunkSize - the size of each read operation, defaults to 8192
      • fromFile$default$2

        public static int fromFile$default$2()
      • fromPath

        public static Source<ByteString,​scala.concurrent.Future<IOResult>> fromPath​(java.nio.file.Path f,
                                                                                          int chunkSize)
        Creates a Source from a files contents. Emitted elements are chunkSize sized ByteString elements, except the final element, which will be up to chunkSize in size.

        You can configure the default dispatcher for this Source by changing the akka.stream.materializer.blocking-io-dispatcher or set it for a given Source by using ActorAttributes.

        It materializes a Future of IOResult containing the number of bytes read from the source file upon completion, and a possible exception if IO operation was not completed successfully. Note that bytes having been read by the source does not give any guarantee that the bytes were seen by downstream stages.

        Parameters:
        f - the file path to read from
        chunkSize - the size of each read operation, defaults to 8192
      • fromPath

        public static Source<ByteString,​scala.concurrent.Future<IOResult>> fromPath​(java.nio.file.Path f,
                                                                                          int chunkSize,
                                                                                          long startPosition)
        Creates a Source from a files contents. Emitted elements are chunkSize sized ByteString elements, except the final element, which will be up to chunkSize in size.

        You can configure the default dispatcher for this Source by changing the akka.stream.materializer.blocking-io-dispatcher or set it for a given Source by using ActorAttributes.

        It materializes a Future of IOResult containing the number of bytes read from the source file upon completion, and a possible exception if IO operation was not completed successfully. Note that bytes having been read by the source does not give any guarantee that the bytes were seen by downstream stages.

        Parameters:
        f - the file path to read from
        chunkSize - the size of each read operation, defaults to 8192
        startPosition - the start position to read from
      • fromPath$default$2

        public static int fromPath$default$2()
      • toFile

        public static Sink<ByteString,​scala.concurrent.Future<IOResult>> toFile​(java.io.File f,
                                                                                      scala.collection.immutable.Set<java.nio.file.OpenOption> options)
        Deprecated.
        Use `toPath` instead. Since 2.4.5.
        Creates a Sink which writes incoming ByteString elements to the given file. Overwrites existing files by truncating their contents as default.

        Materializes a Future of IOResult that will be completed with the size of the file (in bytes) at the streams completion, and a possible exception if IO operation was not completed successfully.

        This source is backed by an Actor which will use the dedicated akka.stream.blocking-io-dispatcher, unless configured otherwise by using ActorAttributes.

        Parameters:
        f - the file to write to
        options - File open options, see StandardOpenOption, defaults to Set(WRITE, TRUNCATE_EXISTING, CREATE)
      • toFile$default$2

        public static scala.collection.immutable.Set<java.nio.file.OpenOption> toFile$default$2()
      • toPath

        public static Sink<ByteString,​scala.concurrent.Future<IOResult>> toPath​(java.nio.file.Path f,
                                                                                      scala.collection.immutable.Set<java.nio.file.OpenOption> options)
        Creates a Sink which writes incoming ByteString elements to the given file path. Overwrites existing files by truncating their contents as default.

        Materializes a Future of IOResult that will be completed with the size of the file (in bytes) at the streams completion, and a possible exception if IO operation was not completed successfully.

        This source is backed by an Actor which will use the dedicated akka.stream.blocking-io-dispatcher, unless configured otherwise by using ActorAttributes.

        Accepts as arguments a set of StandardOpenOption, which will determine the underlying behavior when writing the file. If java.nio.file.StandardOpenOption.SYNC is provided, every update to the file's content be written synchronously to the underlying storage device. Otherwise (the default), the write will be written to the storage device asynchronously by the OS, and may not be stored durably on the storage device at the time the stream completes.

        Parameters:
        f - the file path to write to
        options - File open options, see StandardOpenOption, defaults to Set(WRITE, TRUNCATE_EXISTING, CREATE)
      • toPath

        public static Sink<ByteString,​scala.concurrent.Future<IOResult>> toPath​(java.nio.file.Path f,
                                                                                      scala.collection.immutable.Set<java.nio.file.OpenOption> options,
                                                                                      long startPosition)
        Creates a Sink which writes incoming ByteString elements to the given file path. Overwrites existing files by truncating their contents as default.

        Materializes a Future of IOResult that will be completed with the size of the file (in bytes) at the streams completion, and a possible exception if IO operation was not completed successfully.

        This source is backed by an Actor which will use the dedicated akka.stream.blocking-io-dispatcher, unless configured otherwise by using ActorAttributes.

        Accepts as arguments a set of StandardOpenOption, which will determine the underlying behavior when writing the file. If java.nio.file.StandardOpenOption.SYNC is provided, every update to the file's content be written synchronously to the underlying storage device. Otherwise (the default), the write will be written to the storage device asynchronously by the OS, and may not be stored durably on the storage device at the time the stream completes.

        Parameters:
        f - the file path to write to
        options - File open options, see StandardOpenOption, defaults to Set(WRITE, CREATE)
        startPosition - the start position to write to
      • toPath$default$2

        public static scala.collection.immutable.Set<java.nio.file.OpenOption> toPath$default$2()