Class FileSink<T>

java.lang.Object
org.voltdb.stream.sink.FileSink<T>
Type Parameters:
T - the type of elements consumed by this sink
All Implemented Interfaces:
Consumer<T>, VoltLifecycle, VoltStreamSink<T>

public class FileSink<T> extends Object implements VoltStreamSink<T>
A sink that writes streamed data items to a file within a specified directory.

Each instance of FileSink creates a new file with a unique name in the designated directory. Data items are encoded into bytes and written to the file, each separated by a specified line terminator.

  • Constructor Details

    • FileSink

      public FileSink(String directoryPath)
      Constructs a FileSink with the specified directory path.

      Uses the system's default line separator and a default encoder that converts each input to its string representation in the platform's default charset.

      Parameters:
      directoryPath - the path to the directory where output files will be created
    • FileSink

      public FileSink(String directoryPath, String lineTerminator, Function<T,byte[]> encoder)
      Constructs a FileSink with the specified directory path, line terminator, and encoder.

      This constructor allows customization of the line terminator and the encoding mechanism for input data.

      Parameters:
      directoryPath - the path to the directory where output files will be created
      lineTerminator - the string to append after each encoded data item (e.g., newline)
      encoder - a function that converts each input item to a byte array for writing to the file
  • Method Details

    • configure

      public void configure(ExecutionContext context)
      Specified by:
      configure in interface VoltLifecycle
    • consume

      public void consume(T output)
      Description copied from interface: Consumer
      This method is invoked by any upstream caller, the caller can emmit any number of events to a consumer.
      Specified by:
      consume in interface Consumer<T>
      Parameters:
      output - event
    • commit

      public CommitResult commit(ExecutionContext context)
      Description copied from interface: VoltStreamSink
      the callback is invoked when the sink has to perform any logic assuring data is securely passed to downstream system
      Specified by:
      commit in interface VoltStreamSink<T>
      Parameters:
      context - runtime context
      Returns:
      result of the commit