org.apache.avro.file
Class DataFileWriter<D>

java.lang.Object
  extended by org.apache.avro.file.DataFileWriter<D>

public class DataFileWriter<D>
extends Object

Stores in a file a sequence of data conforming to a schema. The schema is stored in the file with the data. Each datum in a file is of the same schema. Data is written with a 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.

See Also:
DataFileReader

Constructor Summary
DataFileWriter(Schema schema, OutputStream outs, DatumWriter<D> dout)
          Construct a writer to a file for data matching a schema.
 
Method Summary
 void addSchema(Schema branch)
          If the schema for this file is a union, add a branch to it.
 void append(D datum)
          Append a datum to the file.
 void close()
          Close the file.
 void flush()
          Flush the current state of the file, including metadata.
 void setMeta(String key, byte[] value)
          Set a metadata property.
 void setMeta(String key, long value)
          Set a metadata property.
 void setMeta(String key, String value)
          Set a metadata property.
 long sync()
          Return the current position as a value that may be passed to DataFileReader.seek(long).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataFileWriter

public DataFileWriter(Schema schema,
                      OutputStream outs,
                      DatumWriter<D> dout)
               throws IOException
Construct a writer to a file for data matching a schema.

Throws:
IOException
Method Detail

setMeta

public void setMeta(String key,
                    byte[] value)
Set a metadata property.


setMeta

public void setMeta(String key,
                    String value)
Set a metadata property.


setMeta

public void setMeta(String key,
                    long value)
Set a metadata property.


addSchema

public void addSchema(Schema branch)
If the schema for this file is a union, add a branch to it.


append

public void append(D datum)
            throws IOException
Append a datum to the file.

Throws:
IOException

sync

public long sync()
          throws IOException
Return the current position as a value that may be passed to DataFileReader.seek(long). Forces the end of the current block, emitting a synchronization marker.

Throws:
IOException

flush

public void flush()
           throws IOException
Flush the current state of the file, including metadata.

Throws:
IOException

close

public void close()
           throws IOException
Close the file.

Throws:
IOException


Copyright © 2009 The Apache Software Foundation