public class ResolvingDecoder extends ValidatingDecoder
Decoder that performs type-resolution between the reader's and
writer's schemas.
When resolving schemas, this class will return the values of fields in
_writer's_ order, not the reader's order. (However, it returns _only_ the
reader's fields, not any extra fields the writer may have written.) To help
clients handle fields that appear to be coming out of order, this class
defines the method readFieldOrder().
See the parser documentation for information on how this works.
inparser| Modifier and Type | Method and Description |
|---|---|
Symbol |
doAction(Symbol input,
Symbol top)
Handle the action symbol top when the input is
sought to be taken off the stack.
|
void |
drain()
Consume any more data that has been written by the writer but not
needed by the reader so that the the underlying decoder is in proper
shape for the next record.
|
ByteBuffer |
readBytes(ByteBuffer old)
Reads a byte-string written by
Encoder.writeBytes(java.nio.ByteBuffer). |
double |
readDouble()
Reads a double written by
Encoder.writeDouble(double). |
int |
readEnum()
Reads an enumeration.
|
Schema.Field[] |
readFieldOrder()
Returns the actual order in which the reader's fields will be
returned to the reader.
|
float |
readFloat()
Reads a float written by
Encoder.writeFloat(float). |
int |
readIndex()
Reads the tag of a union written by
Encoder.writeIndex(int). |
long |
readLong()
Reads a long written by
Encoder.writeLong(long). |
String |
readString()
Reads a char-string written by
Encoder.writeString(org.apache.avro.util.Utf8). |
Utf8 |
readString(Utf8 old)
Reads a char-string written by
Encoder.writeString(org.apache.avro.util.Utf8). |
static Object |
resolve(Schema writer,
Schema reader)
Produces an opaque resolver that can be used to construct a new
ResolvingDecoder(Object, Decoder). |
void |
skipAction()
Skips the action at the top of the stack.
|
void |
skipBytes()
Discards a byte-string written by
Encoder.writeBytes(java.nio.ByteBuffer). |
void |
skipString()
Discards a char-string written by
Encoder.writeString(org.apache.avro.util.Utf8). |
arrayNext, configure, mapNext, readArrayStart, readBoolean, readFixed, readInt, readMapStart, readNull, skipArray, skipFixed, skipFixed, skipMapskipTopSymbolpublic static Object resolve(Schema writer, Schema reader) throws IOException
ResolvingDecoder(Object, Decoder). The
returned Object is immutable and hence can be simultaneously used
in many ResolvingDecoders. This method is reasonably expensive, the
users are encouraged to cache the result.writer - The writer's schema. Cannot be null.reader - The reader's schema. Cannot be null.IOExceptionpublic final Schema.Field[] readFieldOrder() throws IOException
ResolvingDecoder
returns values in the order written by the writer, rather than
the order expected by the reader. This method allows readers
to figure out what fields to expect. Let's say the reader is
expecting a three-field record, the first field is a long, the
second a string, and the third an array. In this case, a
typical usage might be as follows:
Schema.Fields[] fieldOrder = in.readFieldOrder();
for (int i = 0; i < 3; i++) {
switch (fieldOrder[i].pos()) {
case 1:
foo(in.readLong());
break;
case 2:
someVariable = in.readString();
break;
case 3:
bar(in); // The code of "bar" will read an array-of-int
break;
}
Note that ResolvingDecoder will return only the
fields expected by the reader, not other fields that may have
been written by the writer. Thus, the iteration-count of "3" in
the above loop will always be correct.
Throws a runtime exception if we're not just about to read the
field of a record. Also, this method will consume the field
information, and thus may only be called once before
reading the field value. (However, if the client knows the
order of incoming fields, then the client does not
need to call this method but rather can just start reading the
field values.)AvroTypeException - If we're not starting a new recordIOExceptionpublic final void drain()
throws IOException
IOExceptionpublic long readLong()
throws IOException
DecoderEncoder.writeLong(long).readLong in class ValidatingDecoderIOExceptionpublic float readFloat()
throws IOException
DecoderEncoder.writeFloat(float).readFloat in class ValidatingDecoderIOExceptionpublic double readDouble()
throws IOException
DecoderEncoder.writeDouble(double).readDouble in class ValidatingDecoderIOExceptionpublic Utf8 readString(Utf8 old) throws IOException
DecoderEncoder.writeString(org.apache.avro.util.Utf8).readString in class ValidatingDecoderIOExceptionpublic String readString() throws IOException
DecoderEncoder.writeString(org.apache.avro.util.Utf8).readString in class ValidatingDecoderIOExceptionpublic void skipString()
throws IOException
DecoderEncoder.writeString(org.apache.avro.util.Utf8).skipString in class ValidatingDecoderIOExceptionpublic ByteBuffer readBytes(ByteBuffer old) throws IOException
DecoderEncoder.writeBytes(java.nio.ByteBuffer).
if old is not null and has sufficient capacity to take in
the bytes being read, the bytes are returned in old.readBytes in class ValidatingDecoderIOExceptionpublic void skipBytes()
throws IOException
DecoderEncoder.writeBytes(java.nio.ByteBuffer).skipBytes in class ValidatingDecoderIOExceptionpublic int readEnum()
throws IOException
DecoderreadEnum in class ValidatingDecoderIOExceptionpublic int readIndex()
throws IOException
DecoderEncoder.writeIndex(int).readIndex in class ValidatingDecoderIOExceptionpublic Symbol doAction(Symbol input, Symbol top) throws IOException
Parser.ActionHandlerdoAction in interface Parser.ActionHandlerdoAction in class ValidatingDecoderinput - The input symbol from the caller of advancetop - The symbol at the top the stack.IOExceptionpublic void skipAction()
throws IOException
SkipParser.SkipHandlerskipAction in interface SkipParser.SkipHandlerskipAction in class ParsingDecoderIOExceptionCopyright © 2009–2016 The Apache Software Foundation. All rights reserved.