T
- the type of values to write.public abstract static class FileBasedSink.FileBasedWriter<T> extends Sink.Writer<T,FileBasedSink.FileResult>
Sink.Writer
that writes a bundle to a FileBasedSink
. Subclass
implementations provide a method that can write a single value to a WritableByteChannel
(Sink.Writer.write(T)
).
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.
Modifier and Type | Field and Description |
---|---|
protected String |
mimeType
The MIME type used in the creation of the output channel (if the file system supports it).
|
Constructor and Description |
---|
FileBasedWriter(FileBasedSink.FileBasedWriteOperation<T> writeOperation)
Construct a new FileBasedWriter with a base filename.
|
Modifier and Type | Method and Description |
---|---|
FileBasedSink.FileResult |
close()
Closes the channel and return the bundle result.
|
FileBasedSink.FileBasedWriteOperation<T> |
getWriteOperation()
Return the FileBasedWriteOperation that this Writer belongs to.
|
void |
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.
|
protected void |
writeFooter()
Writes footer at the end of output files.
|
protected void |
writeHeader()
Writes header at the beginning of output files.
|
write
protected String mimeType
GCS, for example, supports writing files with Content-Type metadata.
May be overridden. Default is MimeTypes.TEXT
. See MimeTypes
for other
options.
public FileBasedWriter(FileBasedSink.FileBasedWriteOperation<T> writeOperation)
protected abstract void prepareWrite(WritableByteChannel channel) throws Exception
Called before any subsequent calls to writeHeader, writeFooter, and write.
Exception
protected void writeHeader() throws Exception
Exception
protected void writeFooter() throws Exception
Exception
public final void open(String uId) throws Exception
open
in class Sink.Writer<T,FileBasedSink.FileResult>
Exception
public final FileBasedSink.FileResult close() throws Exception
close
in class Sink.Writer<T,FileBasedSink.FileResult>
Exception
public FileBasedSink.FileBasedWriteOperation<T> getWriteOperation()
getWriteOperation
in class Sink.Writer<T,FileBasedSink.FileResult>