| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.avro.io.Encoder
org.apache.avro.io.ValidatingEncoder
public class ValidatingEncoder
Encoder that ensures that the sequence of operations conforms
 to a schema.
 
See the parser documentation for information on how this works.
| Field Summary | |
|---|---|
| protected  int | pos | 
| protected  int[] | stack | 
| protected  org.apache.avro.io.ParsingTable | table | 
| Constructor Summary | |
|---|---|
| ValidatingEncoder(Schema schema,
                  Encoder out) | |
| Method Summary | |
|---|---|
|  void | flush()Writes any buffered output to the underlying stream. | 
|  void | init(OutputStream out)Redirect output (and reset the parser state if we're checking). | 
|  void | reset()After writing a complete object that conforms to the schema or after an error, if you want to start writing another object, call this method. | 
|  void | setItemCount(long itemCount)Call this method before writing a batch of items in an array or a map. | 
|  void | startItem()Start a new item of an array or map. | 
|  void | writeArrayEnd()Call this method to finish writing an array. | 
|  void | writeArrayStart()Call this method to start writing an array. | 
|  void | writeBoolean(boolean b)Write a boolean value. | 
|  void | writeBytes(byte[] bytes,
           int start,
           int len)Write a byte string. | 
|  void | writeBytes(ByteBuffer bytes)Write a byte string. | 
|  void | writeDouble(double d)Write a double. | 
|  void | writeEnum(int e)Writes an enumeration. | 
|  void | writeFixed(byte[] bytes,
           int start,
           int length)Writes a fixed size binary object. | 
|  void | writeFloat(float f)Write a float. | 
|  void | writeIndex(int unionIndex)Call this method to write the tag of a union. | 
|  void | writeInt(int n)Writes a 32-bit integer. | 
|  void | writeLong(long n)Write a 64-bit integer. | 
|  void | writeMapEnd()Call this method to terminate the inner-most, currently-opened map. | 
|  void | writeMapStart()Call this to start a new map. | 
|  void | writeNull()"Writes" a null value. | 
|  void | writeString(Utf8 utf8)Write a Unicode character string. | 
| Methods inherited from class org.apache.avro.io.Encoder | 
|---|
| writeBytes, writeFixed, writeString | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
protected int[] stack
protected int pos
protected org.apache.avro.io.ParsingTable table
| Constructor Detail | 
|---|
public ValidatingEncoder(Schema schema,
                         Encoder out)
| Method Detail | 
|---|
public void init(OutputStream out)
          throws IOException
Encoder
init in class EncoderIOException
public void flush()
           throws IOException
Encoder
flush in class EncoderIOException
public void writeNull()
               throws IOException
Encoder
writeNull in class EncoderIOException
public void writeBoolean(boolean b)
                  throws IOException
Encoder
writeBoolean in class EncoderIOException
public void writeInt(int n)
              throws IOException
Encoder
writeInt in class EncoderIOException
public void writeLong(long n)
               throws IOException
Encoder
writeLong in class EncoderIOException
public void writeFloat(float f)
                throws IOException
Encoder
writeFloat in class EncoderIOException
public void writeDouble(double d)
                 throws IOException
Encoder
writeDouble in class EncoderIOException
public void writeString(Utf8 utf8)
                 throws IOException
Encoder
writeString in class EncoderIOException
public void writeBytes(ByteBuffer bytes)
                throws IOException
Encoder
writeBytes in class EncoderIOException
public void writeBytes(byte[] bytes,
                       int start,
                       int len)
                throws IOException
Encoder
writeBytes in class EncoderIOException
public void writeFixed(byte[] bytes,
                       int start,
                       int length)
                throws IOException
Encoder
writeFixed in class Encoderbytes - The contents to writestart - The position within bytes where the contents
 start.length - The number of bytes to write.
IOException
public void writeEnum(int e)
               throws IOException
Encoder
writeEnum in class EncoderIOException
public void writeArrayStart()
                     throws IOException
EncoderEncoder.writeArrayStart(). Then, before writing any data for any item
  call Encoder.setItemCount(long) followed by a sequence of
  Encoder.startItem() and the item itself. The number of
  Encoder.startItem() should match the number specified in
  Encoder.setItemCount(long).
  When actually writing the data of the item, you can call any Encoder method (e.g., Encoder.writeLong(long)).  When all items
  of the array have been written, call Encoder.writeArrayEnd().
  As an example, let's say you want to write an array of records,
  the record consisting of an Long field and a Boolean field.
  Your code would look something like this:
  
  out.writeArrayStart();
  out.setItemCount(list.size());
  for (Record r : list) {
    out.startItem();
    out.writeLong(r.longField);
    out.writeBoolean(r.boolField);
  }
  out.writeArrayEnd();
  
writeArrayStart in class EncoderIOException
public void setItemCount(long itemCount)
                  throws IOException
EncoderEncoder.startItem() followed by any of the
 other write methods of Encoder. The number of calls
 to Encoder.startItem() must be equal to the count specified
 in Encoder.setItemCount(long). Once a batch is completed you
 can start another batch with Encoder.setItemCount(long).
setItemCount in class EncoderitemCount - The number of Encoder.startItem() calls to follow.
IOException
public void startItem()
               throws IOException
EncoderEncoder.writeArrayStart() for usage information.
startItem in class EncoderIOException
public void writeArrayEnd()
                   throws IOException
EncoderEncoder.writeArrayStart() for usage information.
writeArrayEnd in class EncoderIOException
public void writeMapStart()
                   throws IOException
EncoderEncoder.writeArrayStart() for details on usage.
 As an example of usage, let's say you want to write a map of
 records, the record consisting of an Long field and a Boolean
 field.  Your code would look something like this:
 out.writeMapStart(); out.setItemCount(list.size()); for (Map.Entryentry : map.entrySet()) { out.startItem(); out.writeString(entry.getKey()); out.writeLong(entry.getValue().longField); out.writeBoolean(entry.getValue().boolField); } out.writeMapEnd(); 
writeMapStart in class EncoderIOException
public void writeMapEnd()
                 throws IOException
EncoderEncoder.writeArrayStart() for more details.
writeMapEnd in class EncoderIOException
public void writeIndex(int unionIndex)
                throws IOException
Encoderout.writeIndex(1); out.writeLong(record.longField); out.writeBoolean(record.boolField);
writeIndex in class EncoderIOExceptionpublic void reset()
| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||