Google Cloud Dataflow SDK for Java, version 1.9.1
- Type Parameters:
T- the type of values to write.
- Direct Known Subclasses:
public abstract static class FileBasedSink.FileBasedWriter<T> extends Sink.Writer<T,FileBasedSink.FileResult>Abstract
Sink.Writerthat writes a bundle to a
FileBasedSink. Subclass implementations provide a method that can write a single value to a
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 FileBasedWriter instances may be created on the same worker, and therefore any access to static members or methods should be thread safe.
Fields Modifier and Type Field and Description
mimeTypeThe MIME type used in the creation of the output channel (if the file system supports it).
Constructors Constructor and Description
FileBasedWriter(FileBasedSink.FileBasedWriteOperation<T> writeOperation)Construct a new FileBasedWriter with a base filename.
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description
close()Closes the channel and return the bundle result.
getWriteOperation()Return the FileBasedWriteOperation that this Writer belongs to.
open(String uId)Opens the channel.
protected abstract void
prepareWrite(WritableByteChannel channel)Called with the channel that a subclass will write its header, footer, and values to.
writeFooter()Writes footer at the end of output files.
writeHeader()Writes header at the beginning of output files.
protected String mimeTypeThe MIME type used in the creation of the output channel (if the file system supports it).
GCS, for example, supports writing files with Content-Type metadata.
May be overridden. Default is
MimeTypesfor other options.
protected abstract void prepareWrite(WritableByteChannel channel) throws ExceptionCalled 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.
protected void writeHeader() throws ExceptionWrites header at the beginning of output files. Nothing by default; subclasses may override.
protected void writeFooter() throws ExceptionWrites footer at the end of output files. Nothing by default; subclasses may override.
openOpens the channel.
public final FileBasedSink.FileResult close() throws ExceptionCloses the channel and return the bundle result.