| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.avro.io.Encoder
public abstract class Encoder
Low-level support for serializing Avro values.
 This class has two types of methods.  One type of methods support
 the writing of leaf values (for example, writeLong(long) and
 writeString(org.apache.avro.util.Utf8)).  These methods have analogs in Decoder.
 The other type of methods support the writing of maps and arrays.
 These methods are writeArrayStart(), startItem(), and writeArrayEnd() (and similar methods for
 maps).  Some implementations of Encoder handle the
 buffering required to break large maps and arrays into blocks,
 which is necessary for applications that want to do streaming.
 (See writeArrayStart() for details on these methods.)
Decoder| Constructor Summary | |
|---|---|
| Encoder() | |
| Method Summary | |
|---|---|
| abstract  void | init(OutputStream out)Redirect output (and reset the parser state if we're checking). | 
| abstract  void | setItemCount(long itemCount)Call this method before writing a batch of items in an array or a map. | 
| abstract  void | startItem()Start a new item of an array or map. | 
| abstract  void | writeArrayEnd()Call this method to finish writing an array. | 
| abstract  void | writeArrayStart()Call this method to start writing an array. | 
| abstract  void | writeBoolean(boolean b)Write a boolean value. | 
|  void | writeBytes(byte[] bytes)Writes a byte string. | 
| abstract  void | writeBytes(byte[] bytes,
           int start,
           int len)Write a byte string. | 
| abstract  void | writeBytes(ByteBuffer bytes)Write a byte string. | 
| abstract  void | writeDouble(double d)Write a double. | 
| abstract  void | writeEnum(int e)Writes an enumeration. | 
|  void | writeFixed(byte[] bytes)A shorthand for writeFixed(bytes, 0, bytes.length) | 
| abstract  void | writeFixed(byte[] bytes,
           int start,
           int len)Writes a fixed size binary object. | 
| abstract  void | writeFloat(float f)Write a float. | 
| abstract  void | writeIndex(int unionIndex)Call this method to write the tag of a union. | 
| abstract  void | writeInt(int n)Writes a 32-bit integer. | 
| abstract  void | writeLong(long n)Write a 64-bit integer. | 
| abstract  void | writeMapEnd()Call this method to terminate the inner-most, currently-opened map. | 
| abstract  void | writeMapStart()Call this to start a new map. | 
| abstract  void | writeNull()"Writes" a null value. | 
|  void | writeString(CharSequence charSequence)Write a Unicode character string. | 
|  void | writeString(String str)Write a Unicode character string. | 
| abstract  void | writeString(Utf8 utf8)Write a Unicode character string. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Methods inherited from interface java.io.Flushable | 
|---|
| flush | 
| Constructor Detail | 
|---|
public Encoder()
| Method Detail | 
|---|
public abstract void init(OutputStream out)
                   throws IOException
IOException
public abstract void writeNull()
                        throws IOException
AvroTypeException - If this is a stateful writer and a
         null is not expected
IOException
public abstract void writeBoolean(boolean b)
                           throws IOException
AvroTypeException - If this is a stateful writer and a
 boolean is not expected
IOException
public abstract void writeInt(int n)
                       throws IOException
AvroTypeException - If this is a stateful writer and an
 integer is not expected
IOException
public abstract void writeLong(long n)
                        throws IOException
AvroTypeException - If this is a stateful writer and a
 long is not expected
IOException
public abstract void writeFloat(float f)
                         throws IOException
IOException
AvroTypeException - If this is a stateful writer and a
 float is not expected
public abstract void writeDouble(double d)
                          throws IOException
AvroTypeException - If this is a stateful writer and a
 double is not expected
IOException
public abstract void writeString(Utf8 utf8)
                          throws IOException
AvroTypeException - If this is a stateful writer and a
 char-string is not expected
IOException
public void writeString(String str)
                 throws IOException
Utf8.  Some Encoder 
 implementations may want to do something different as a performance optimization.
AvroTypeException - If this is a stateful writer and a
 char-string is not expected
IOException
public void writeString(CharSequence charSequence)
                 throws IOException
Utf8 it writes this directly, otherwise
 the CharSequence is converted to a String via toString() and written.
AvroTypeException - If this is a stateful writer and a
 char-string is not expected
IOException
public abstract void writeBytes(ByteBuffer bytes)
                         throws IOException
AvroTypeException - If this is a stateful writer and a
         byte-string is not expected
IOException
public abstract void writeBytes(byte[] bytes,
                                int start,
                                int len)
                         throws IOException
AvroTypeException - If this is a stateful writer and a
 byte-string is not expected
IOException
public void writeBytes(byte[] bytes)
                throws IOException
IOException
AvroTypeException - If this is a stateful writer and a
 byte-string is not expected
public abstract void writeFixed(byte[] bytes,
                                int start,
                                int len)
                         throws IOException
bytes - The contents to writestart - The position within bytes where the contents
 start.len - The number of bytes to write.
AvroTypeException - If this is a stateful writer and a
 byte-string is not expected
IOException
public void writeFixed(byte[] bytes)
                throws IOException
bytes - 
IOException
public abstract void writeEnum(int e)
                        throws IOException
e - 
AvroTypeException - If this is a stateful writer and an enumeration
 is not expected or the e is out of range.
IOException
public abstract void writeArrayStart()
                              throws IOException
writeArrayStart(). Then, before writing any data for any item
  call setItemCount(long) followed by a sequence of
  startItem() and the item itself. The number of
  startItem() should match the number specified in
  setItemCount(long).
  When actually writing the data of the item, you can call any Encoder method (e.g., writeLong(long)).  When all items
  of the array have been written, call 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();
  
AvroTypeException - If this is a stateful writer and an
          array is not expected
IOException
public abstract void setItemCount(long itemCount)
                           throws IOException
startItem() followed by any of the
 other write methods of Encoder. The number of calls
 to startItem() must be equal to the count specified
 in setItemCount(long). Once a batch is completed you
 can start another batch with setItemCount(long).
itemCount - The number of startItem() calls to follow.
IOException
public abstract void startItem()
                        throws IOException
writeArrayStart() for usage information.
AvroTypeException - If called outside of an array or map context
IOException
public abstract void writeArrayEnd()
                            throws IOException
writeArrayStart() for usage information.
AvroTypeException - If items written does not match count
          provided to writeArrayStart()
AvroTypeException - If not currently inside an array
IOException
public abstract void writeMapStart()
                            throws IOException
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(); 
AvroTypeException - If this is a stateful writer and a
 map is not expected
IOException
public abstract void writeMapEnd()
                          throws IOException
writeArrayStart() for more details.
AvroTypeException - If items written does not match count
          provided to writeMapStart()
AvroTypeException - If not currently inside a map
IOException
public abstract void writeIndex(int unionIndex)
                         throws IOException
out.writeIndex(1); out.writeLong(record.longField); out.writeBoolean(record.boolField);
AvroTypeException - If this is a stateful writer and a
 map is not expected
IOException| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||