Class FileIO

java.lang.Object
org.apache.pekko.stream.javadsl.FileIO

public class FileIO extends Object
Java API: Factories to create sinks and sources from files
  • Constructor Details

    • FileIO

      public FileIO()
  • Method Details

    • toPath

      public static Sink<ByteString,CompletionStage<IOResult>> toPath(Path f)
      Creates a Sink that writes incoming pekko.util.ByteString elements to the given file path. Overwrites existing files by truncating their contents, if you want to append to an existing file {@link toPath(Path, util.Set[OpenOption])} with java.nio.file.StandardOpenOption.APPEND.

      Materializes a CompletionStage 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.

      You can configure the default dispatcher for this Source by changing the pekko.stream.materializer.blocking-io-dispatcher or set it for a given Source by using pekko.stream.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
    • toPath

      public static <Opt extends OpenOption> Sink<ByteString,CompletionStage<IOResult>> toPath(Path f, Set<Opt> options)
      Creates a Sink that writes incoming pekko.util.ByteString elements to the given file path.

      Materializes a CompletionStage 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.

      You can configure the default dispatcher for this Source by changing the pekko.stream.materializer.blocking-io-dispatcher or set it for a given Source by using pekko.stream.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
    • toPath

      public static <Opt extends OpenOption> Sink<ByteString,CompletionStage<IOResult>> toPath(Path f, Set<Opt> options, long startPosition)
      Creates a Sink that writes incoming pekko.util.ByteString elements to the given file path.

      Materializes a CompletionStage 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.

      You can configure the default dispatcher for this Source by changing the pekko.stream.materializer.blocking-io-dispatcher or set it for a given Source by using pekko.stream.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
      startPosition - startPosition the start position to read from, defaults to 0
    • fromPath

      public static Source<ByteString,CompletionStage<IOResult>> fromPath(Path f)
      Creates a Source from a files contents. Emitted elements are pekko.util.ByteString elements, chunked by default by 8192 bytes, except the last element, which will be up to 8192 in size.

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

      It materializes a CompletionStage 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
    • fromPath

      public static Source<ByteString,CompletionStage<IOResult>> fromPath(Path f, int chunkSize)
      Creates a synchronous Source from a files contents. Emitted elements are chunkSize sized pekko.util.ByteString elements, except the last element, which will be up to chunkSize in size.

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

      It materializes a CompletionStage 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
    • fromPath

      public static Source<ByteString,CompletionStage<IOResult>> fromPath(Path f, int chunkSize, long startPosition)
      Creates a synchronous Source from a files contents. Emitted elements are chunkSize sized pekko.util.ByteString elements, except the last element, which will be up to chunkSize in size.

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

      It materializes a CompletionStage 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
      startPosition - startPosition the start position to read from, defaults to 0