public class DataFileWriter<D> extends Object implements Closeable, Flushable
DatumWriter
. Data is grouped into
blocks. A synchronization marker is written between blocks, so that
files may be split. Blocks may be compressed. Extensible metadata is stored
at the end of the file. Files may be appended to.DataFileReader
Modifier and Type | Class and Description |
---|---|
static class |
DataFileWriter.AppendWriteException
Thrown by
append(Object) when an exception occurs while writing a
datum to the buffer. |
Constructor and Description |
---|
DataFileWriter(DatumWriter<D> dout)
Construct a writer, not yet open.
|
Modifier and Type | Method and Description |
---|---|
void |
append(D datum)
Append a datum to the file.
|
void |
appendAllFrom(DataFileStream<D> otherFile,
boolean recompress)
Appends data from another file.
|
void |
appendEncoded(ByteBuffer datum)
Expert: Append a pre-encoded datum to the file.
|
DataFileWriter<D> |
appendTo(File file)
Open a writer appending to an existing file.
|
DataFileWriter<D> |
appendTo(SeekableInput in,
OutputStream out)
Open a writer appending to an existing file.
|
void |
close()
Flush and close the file.
|
DataFileWriter<D> |
create(Schema schema,
File file)
Open a new file for data matching a schema with a random sync.
|
DataFileWriter<D> |
create(Schema schema,
OutputStream outs)
Open a new file for data matching a schema with a random sync.
|
DataFileWriter<D> |
create(Schema schema,
OutputStream outs,
byte[] sync)
Open a new file for data matching a schema with an explicit sync.
|
void |
flush()
Calls sync() and then flushes the current state of the file.
|
void |
fSync()
If this writer was instantiated using a File or using an
Syncable instance, this method flushes all buffers for this
writer to disk.
|
boolean |
isFlushOnEveryBlock() |
static boolean |
isReservedMeta(String key) |
DataFileWriter<D> |
setCodec(CodecFactory c)
Configures this writer to use the given codec.
|
void |
setFlushOnEveryBlock(boolean flushOnEveryBlock)
Set whether this writer should flush the block to the stream every time a
sync marker is written.
|
DataFileWriter<D> |
setMeta(String key,
byte[] value)
Set a metadata property.
|
DataFileWriter<D> |
setMeta(String key,
long value)
Set a metadata property.
|
DataFileWriter<D> |
setMeta(String key,
String value)
Set a metadata property.
|
DataFileWriter<D> |
setSyncInterval(int syncInterval)
Set the synchronization interval for this file, in bytes.
|
long |
sync()
Return the current position as a value that may be passed to
DataFileReader.seek(long) . |
public DataFileWriter(DatumWriter<D> dout)
public DataFileWriter<D> setCodec(CodecFactory c)
public DataFileWriter<D> setSyncInterval(int syncInterval)
syncInterval
- the approximate number of uncompressed bytes to write in
each blockpublic DataFileWriter<D> create(Schema schema, File file) throws IOException
IOException
public DataFileWriter<D> create(Schema schema, OutputStream outs) throws IOException
IOException
public DataFileWriter<D> create(Schema schema, OutputStream outs, byte[] sync) throws IOException
IOException
public void setFlushOnEveryBlock(boolean flushOnEveryBlock)
flushOnEveryBlock
- - If set to false, this writer will not flush the
block to the stream until flush() is
explicitly called.public boolean isFlushOnEveryBlock()
public DataFileWriter<D> appendTo(File file) throws IOException
IOException
public DataFileWriter<D> appendTo(SeekableInput in, OutputStream out) throws IOException
in
- reading the existing file.out
- positioned at the end of the existing file.IOException
public DataFileWriter<D> setMeta(String key, byte[] value)
public static boolean isReservedMeta(String key)
public DataFileWriter<D> setMeta(String key, String value)
public DataFileWriter<D> setMeta(String key, long value)
public void append(D datum) throws IOException
IOException
DataFileWriter.AppendWriteException
public void appendEncoded(ByteBuffer datum) throws IOException
IOException
public void appendAllFrom(DataFileStream<D> otherFile, boolean recompress) throws IOException
otherFile
- recompress
- IOException
public long sync() throws IOException
DataFileReader.seek(long)
. Forces the end of the current block,
emitting a synchronization marker. By default, this will also flush the block
to the stream.
If setFlushOnEveryBlock(boolean) is called with param set to
false, then this method may not flush the block. In this case, the
flush() must be called to flush the stream.IOException
public void flush() throws IOException
flush
in interface Flushable
IOException
public void fSync() throws IOException
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2009–2021 The Apache Software Foundation. All rights reserved.