Package org.apache.beam.sdk.io
Class FileBasedSink.Writer<DestinationT,OutputT>
java.lang.Object
org.apache.beam.sdk.io.FileBasedSink.Writer<DestinationT,OutputT>
- Type Parameters:
OutputT
- the type of values to write.
- Enclosing class:
FileBasedSink<UserT,
DestinationT, OutputT>
Abstract writer that writes a bundle to a
FileBasedSink
. Subclass implementations
provide a method that can write a single value to a WritableByteChannel
.
Subclass implementations may also override methods that write headers and footers before and after the values in a bundle, respectively, as well as provide a MIME type for the output channel.
Multiple FileBasedSink.Writer
instances may be created on the same worker, and therefore any
access to static members or methods should be thread safe.
-
Constructor Summary
ConstructorsConstructorDescriptionWriter
(FileBasedSink.WriteOperation<DestinationT, OutputT> writeOperation, String mimeType) Construct a newFileBasedSink.Writer
that will produce files of the given MIME type. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
cleanup()
final void
close()
Closes the channel and returns the bundle result.protected void
Return the user destination object for this writer.Return the WriteOperation that this Writer belongs to.final void
Opens a uniquely named temporary file and initializes the writer usingprepareWrite(java.nio.channels.WritableByteChannel)
.protected abstract void
prepareWrite
(WritableByteChannel channel) Called with the channel that a subclass will write its header, footer, and values to.abstract void
Called for each value in the bundle.protected void
Writes footer at the end of output files.protected void
Writes header at the beginning of output files.
-
Constructor Details
-
Writer
Construct a newFileBasedSink.Writer
that will produce files of the given MIME type.
-
-
Method Details
-
prepareWrite
Called with the channel that a subclass will write its header, footer, and values to. Subclasses should either keep a reference to the channel provided or create and keep a reference to an appropriate object that they will use to write to it.Called before any subsequent calls to writeHeader, writeFooter, and write.
- Throws:
Exception
-
writeHeader
Writes header at the beginning of output files. Nothing by default; subclasses may override.- Throws:
Exception
-
finishWrite
Called after all calls towriteHeader()
,write(OutputT)
andwriteFooter()
. If any resources opened in the write processes need to be flushed, flush them here.- Throws:
Exception
-
open
Opens a uniquely named temporary file and initializes the writer usingprepareWrite(java.nio.channels.WritableByteChannel)
.The unique id that is given to open should be used to ensure that the writer's output does not interfere with the output of other Writers, as a bundle may be executed many times for fault tolerance.
- Throws:
Exception
-
write
Called for each value in the bundle.- Throws:
Exception
-
getOutputFile
-
cleanup
- Throws:
Exception
-
close
Closes the channel and returns the bundle result.- Throws:
Exception
-
getWriteOperation
Return the WriteOperation that this Writer belongs to. -
getDestination
Return the user destination object for this writer.
-