Class FileBasedStateOutputStream

java.lang.Object
java.io.OutputStream
org.apache.flink.core.fs.FSDataOutputStream
org.apache.flink.runtime.state.CheckpointStateOutputStream
org.apache.flink.runtime.state.filesystem.FileBasedStateOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public final class FileBasedStateOutputStream extends CheckpointStateOutputStream
A CheckpointStateOutputStream that writes into a specified file and returns a FileStateHandle upon closing.

Unlike the FsCheckpointStreamFactory.FsCheckpointStateOutputStream, this stream does not have a threshold below which it returns a memory byte stream handle, and does not create random files, but writes to a specified file.

  • Constructor Details

    • FileBasedStateOutputStream

      public FileBasedStateOutputStream(org.apache.flink.core.fs.FileSystem fileSystem, org.apache.flink.core.fs.Path path) throws IOException
      Throws:
      IOException
  • Method Details

    • write

      public final void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • write

      public final void write(@Nonnull byte[] b, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • getPos

      public long getPos() throws IOException
      Specified by:
      getPos in class org.apache.flink.core.fs.FSDataOutputStream
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class org.apache.flink.core.fs.FSDataOutputStream
      Throws:
      IOException
    • sync

      public void sync() throws IOException
      Specified by:
      sync in class org.apache.flink.core.fs.FSDataOutputStream
      Throws:
      IOException
    • isClosed

      public boolean isClosed()
    • close

      public void close()
      Description copied from class: CheckpointStateOutputStream
      This method should close the stream, if has not been closed before. If this method actually closes the stream, it should delete/release the resource behind the stream, such as the file that the stream writes to.

      The above implies that this method is intended to be the "unsuccessful close", such as when cancelling the stream writing, or when an exception occurs. Closing the stream for the successful case must go through CheckpointStateOutputStream.closeAndGetHandle().

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class CheckpointStateOutputStream
    • closeAndGetHandle

      @Nullable public FileStateHandle closeAndGetHandle() throws IOException
      Description copied from class: CheckpointStateOutputStream
      Closes the stream and gets a state handle that can create an input stream producing the data written to this stream.

      This closing must be called (also when the caller is not interested in the handle) to successfully close the stream and retain the produced resource. In contrast, the CheckpointStateOutputStream.close() method removes the target resource when called.

      Specified by:
      closeAndGetHandle in class CheckpointStateOutputStream
      Returns:
      A state handle that can create an input stream producing the data written to this stream.
      Throws:
      IOException - Thrown, if the stream cannot be closed.