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()
Close the file.
|
DataFileWriter<D> |
create(Schema schema,
File file)
Open a new file for data matching a schema.
|
DataFileWriter<D> |
create(Schema schema,
OutputStream outs)
Open a new file for data matching a schema.
|
void |
flush()
Flush the current state of the file.
|
static boolean |
isReservedMeta(String key) |
DataFileWriter<D> |
setCodec(CodecFactory c)
Configures this writer to use the given codec.
|
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> 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.IOException
public void flush() throws IOException
flush
in interface Flushable
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2009-2013 The Apache Software Foundation. All Rights Reserved.