@NotThreadSafe public final class StreamDataFileWriter extends Object implements TimestampCloseable, Flushable, FileWriter<co.cask.cdap.api.flow.flowlet.StreamEvent>
event_file = <header> <data>* <end_marker>
header = "E" "1" <properties>
properties = Avro encoded with the properties schema
data = <timestamp> <length> <stream_event>+
timestamp = 8 bytes int64 for timestamp in milliseconds
length = Avro encoded int32 for size in bytes for all <stream_event>s
stream_event = Avro encoded bytes according to the StreamData schema
end_marker = 8 bytes int64 with value == -(close_timestamp)
Stream index file:
meta_file = <header> <index>*
header = "I" "1" <properties>
properties = Avro encoded with the properties schema
index = <timestamp> <offset>
timestamp = 8 bytes int64 for timestamp in milliseconds
offset = 8 bytes int64 for offset to data block in the event file
| Constructor and Description |
|---|
StreamDataFileWriter(com.google.common.io.OutputSupplier<? extends OutputStream> eventOutputSupplier,
com.google.common.io.OutputSupplier<? extends OutputStream> indexOutputSupplier,
long indexInterval)
Constructs a new instance that writes to given outputs.
|
StreamDataFileWriter(com.google.common.io.OutputSupplier<? extends OutputStream> eventOutputSupplier,
com.google.common.io.OutputSupplier<? extends OutputStream> indexOutputSupplier,
long indexInterval,
Map<String,String> properties)
Constructs a new instance that writes to given outputs.
|
| Modifier and Type | Method and Description |
|---|---|
void |
append(co.cask.cdap.api.flow.flowlet.StreamEvent event)
Appends an event to the file.
|
void |
appendAll(Iterator<? extends co.cask.cdap.api.flow.flowlet.StreamEvent> events)
Writes multiple events to the stream file.
|
void |
close() |
void |
flush() |
long |
getCloseTimestamp()
Returns timestamp in milliseconds when the close operation happened.
|
public StreamDataFileWriter(com.google.common.io.OutputSupplier<? extends OutputStream> eventOutputSupplier, com.google.common.io.OutputSupplier<? extends OutputStream> indexOutputSupplier, long indexInterval) throws IOException
StreamDataFileWriter(OutputSupplier, OutputSupplier, long, Map)
with an empty property map.IOExceptionpublic StreamDataFileWriter(com.google.common.io.OutputSupplier<? extends OutputStream> eventOutputSupplier, com.google.common.io.OutputSupplier<? extends OutputStream> indexOutputSupplier, long indexInterval, Map<String,String> properties) throws IOException
eventOutputSupplier - the provider of the OutputStream for writing eventsindexOutputSupplier - the provider of the OutputStream for writing the indexindexInterval - the time interval in milliseconds for emitting a new index entryproperties - the property set that will be stored as file propertiesIOException - if there is an error in preparing the output streamspublic void append(co.cask.cdap.api.flow.flowlet.StreamEvent event)
throws IOException
FileWriterappend in interface FileWriter<co.cask.cdap.api.flow.flowlet.StreamEvent>event - event to appendIOException - if fail to appendpublic void appendAll(Iterator<? extends co.cask.cdap.api.flow.flowlet.StreamEvent> events) throws IOException
appendAll in interface FileWriter<co.cask.cdap.api.flow.flowlet.StreamEvent>events - an Iterator that provides events to appendIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic void flush()
throws IOException
flush in interface FlushableIOExceptionpublic long getCloseTimestamp()
TimestampCloseablegetCloseTimestamp in interface TimestampCloseableCopyright © 2016 Cask Data, Inc. Licensed under the Apache License, Version 2.0.