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
IOExceptionpublic DataFileWriter<D> create(Schema schema, OutputStream outs) throws IOException
IOExceptionpublic DataFileWriter<D> appendTo(File file) throws IOException
IOExceptionpublic DataFileWriter<D> appendTo(SeekableInput in, OutputStream out) throws IOException
in - reading the existing file.out - positioned at the end of the existing file.IOExceptionpublic 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
IOExceptionDataFileWriter.AppendWriteExceptionpublic void appendEncoded(ByteBuffer datum) throws IOException
IOExceptionpublic void appendAllFrom(DataFileStream<D> otherFile, boolean recompress) throws IOException
otherFile - recompress - IOExceptionpublic long sync()
throws IOException
DataFileReader.seek(long). Forces the end of the current block,
emitting a synchronization marker.IOExceptionpublic void flush()
throws IOException
flush in interface FlushableIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2009-2012 The Apache Software Foundation. All Rights Reserved.