Top Description Inners Fields Constructors Methods
org.apache.avro.io

public Class JsonDecoder

extends ParsingDecoder
implements ActionHandler
Class Inheritance
All Implemented Interfaces
org.apache.avro.io.parsing.Parser.ActionHandler
Imports
java.io.EOFException, .IOException, .InputStream, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.HashMap, .Map, .Objects, .Stack, org.apache.avro.AvroTypeException, .Schema, org.apache.avro.io.parsing.JsonGrammarGenerator, .Parser, .Symbol, org.apache.avro.util.Utf8, com.fasterxml.jackson.core.JsonFactory, .JsonParser, .JsonToken, com.fasterxml.jackson.databind.util.TokenBuffer

A Decoder for Avro's JSON data encoding.

Construct using DecoderFactory.

JsonDecoder is not thread-safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv JsonDecoder.ReorderBuffer
private JsonParser
private static JsonFactory
pack-priv Stack<JsonDecoder.ReorderBuffer>
Inherited from org.apache.avro.io.ParsingDecoder:
parser

Constructor Summary

AccessConstructor and Description
private
private
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
advance(Symbol symbol)

public long
arrayNext()

Implements abstract org.apache.avro.io.Decoder.arrayNext.

Processes the next block of an array and returns the number of items in the block and let's the caller read those items.
private void
checkFixed(int size)

public JsonDecoder

Returns:

this JsonDecoder
configure
(InputStream
The InputStream to read from. Cannot be null.
in
)

Reconfigures this JsonDecoder to use the InputStream provided.

public JsonDecoder

Returns:

this JsonDecoder
configure
(String
The String to read from. Cannot be null.
in
)

Reconfigures this JsonDecoder to use the String provided for input.

public Symbol
doAction(Symbol
The input symbol from the caller of advance
input
,
Symbol
The symbol at the top the stack.
top
)

Implements org.apache.avro.io.parsing.Parser.ActionHandler.doAction.

Handle the action symbol top when the input is sought to be taken off the stack.
private long
private long
private void
doSkipFixed(int length)

private AvroTypeException
error(String type)

private static Symbol
getSymbol(Schema schema)

public long
mapNext()

Implements abstract org.apache.avro.io.Decoder.mapNext.

Processes the next block of map entries and returns the count of them.
public long
readArrayStart()

Implements abstract org.apache.avro.io.Decoder.readArrayStart.

Reads and returns the size of the first block of an array.
public boolean
readBoolean()

Implements abstract org.apache.avro.io.Decoder.readBoolean.

Reads a boolean value written by Encoder#writeBoolean.
private byte[]
public ByteBuffer
readBytes(ByteBuffer old)

Implements abstract org.apache.avro.io.Decoder.readBytes.

Reads a byte-string written by Encoder#writeBytes.
public double
readDouble()

Implements abstract org.apache.avro.io.Decoder.readDouble.

Reads a double written by Encoder#writeDouble.
public int
readEnum()

Implements abstract org.apache.avro.io.Decoder.readEnum.

Reads an enumeration.
public void
readFixed(byte[]
The buffer to store the contents being read.
bytes
,
int
The position where the data needs to be written.
start
,
int
The size of the binary object.
len
)

Implements abstract org.apache.avro.io.Decoder.readFixed.

Reads fixed sized binary object.
public float
readFloat()

Implements abstract org.apache.avro.io.Decoder.readFloat.

Reads a float written by Encoder#writeFloat.
public int
readIndex()

Implements abstract org.apache.avro.io.Decoder.readIndex.

Reads the tag of a union written by Encoder#writeIndex.
public int
readInt()

Implements abstract org.apache.avro.io.Decoder.readInt.

Reads an integer written by Encoder#writeInt.
public long
readLong()

Implements abstract org.apache.avro.io.Decoder.readLong.

Reads a long written by Encoder#writeLong.
public long
readMapStart()

Implements abstract org.apache.avro.io.Decoder.readMapStart.

Reads and returns the size of the next block of map-entries.
public void
readNull()

Implements abstract org.apache.avro.io.Decoder.readNull.

"Reads" a null value.
public Utf8
readString(Utf8 old)

Implements abstract org.apache.avro.io.Decoder.readString.

Reads a char-string written by Encoder#writeString.
public String
readString()

Implements abstract org.apache.avro.io.Decoder.readString.

Reads a char-string written by Encoder#writeString.
public long
skipArray()

Implements abstract org.apache.avro.io.Decoder.skipArray.

Used for quickly skipping through an array.
public void
skipBytes()

Implements abstract org.apache.avro.io.Decoder.skipBytes.

Discards a byte-string written by Encoder#writeBytes.
public void
skipFixed(int
The size of the binary object to be skipped.
length
)

Implements abstract org.apache.avro.io.Decoder.skipFixed.

Discards fixed sized binary object.
protected void
public long
skipMap()

Implements abstract org.apache.avro.io.Decoder.skipMap.

Support for quickly skipping through a map similar to skipArray.
public void
skipString()

Implements abstract org.apache.avro.io.Decoder.skipString.

Discards a char-string written by Encoder#writeString.
Inherited from org.apache.avro.io.ParsingDecoder:
skipActionskipTopSymbol

Field Detail

currentReorderBufferback to summary
pack-priv JsonDecoder.ReorderBuffer currentReorderBuffer
inback to summary
private JsonParser in
jsonFactoryback to summary
private static JsonFactory jsonFactory
reorderBuffersback to summary
pack-priv Stack<JsonDecoder.ReorderBuffer> reorderBuffers

Constructor Detail

JsonDecoderback to summary
private JsonDecoder(Symbol root, InputStream in) throws IOException
JsonDecoderback to summary
private JsonDecoder(Symbol root, String in) throws IOException
JsonDecoderback to summary
pack-priv JsonDecoder(Schema schema, InputStream in) throws IOException
JsonDecoderback to summary
pack-priv JsonDecoder(Schema schema, String in) throws IOException

Method Detail

advanceback to summary
private void advance(Symbol symbol) throws IOException
arrayNextback to summary
public long arrayNext() throws IOException

Implements abstract org.apache.avro.io.Decoder.arrayNext.

Doc from org.apache.avro.io.Decoder.arrayNext.

Processes the next block of an array and returns the number of items in the block and let's the caller read those items.

Annotations
@Override
checkFixedback to summary
private void checkFixed(int size) throws IOException
configureback to summary
public JsonDecoder configure(InputStream in) throws IOException

Reconfigures this JsonDecoder to use the InputStream provided.

If the InputStream provided is null, a NullPointerException is thrown.

Otherwise, this JsonDecoder will reset its state and then reconfigure its input.

Parameters
in:InputStream

The InputStream to read from. Cannot be null.

Returns:JsonDecoder

this JsonDecoder

Exceptions
NullPointerException:
if in is null
configureback to summary
public JsonDecoder configure(String in) throws IOException

Reconfigures this JsonDecoder to use the String provided for input.

If the String provided is null, a NullPointerException is thrown.

Otherwise, this JsonDecoder will reset its state and then reconfigure its input.

Parameters
in:String

The String to read from. Cannot be null.

Returns:JsonDecoder

this JsonDecoder

Exceptions
NullPointerException:
if in is null
doActionback to summary
public Symbol doAction(Symbol input, Symbol top) throws IOException

Implements org.apache.avro.io.parsing.Parser.ActionHandler.doAction.

Doc from org.apache.avro.io.parsing.Parser.ActionHandler.doAction.

Handle the action symbol top when the input is sought to be taken off the stack.

Parameters
input:Symbol

The input symbol from the caller of advance

top:Symbol

The symbol at the top the stack.

Returns:Symbol

null if advance() is to continue processing the stack. If not null the return value will be returned by advance().

Annotations
@Override
doArrayNextback to summary
private long doArrayNext() throws IOException
doMapNextback to summary
private long doMapNext() throws IOException
doSkipFixedback to summary
private void doSkipFixed(int length) throws IOException
errorback to summary
private AvroTypeException error(String type)
getSymbolback to summary
private static Symbol getSymbol(Schema schema)
mapNextback to summary
public long mapNext() throws IOException

Implements abstract org.apache.avro.io.Decoder.mapNext.

Doc from org.apache.avro.io.Decoder.mapNext.

Processes the next block of map entries and returns the count of them. Similar to arrayNext. See readMapStart for details.

Annotations
@Override
readArrayStartback to summary
public long readArrayStart() throws IOException

Implements abstract org.apache.avro.io.Decoder.readArrayStart.

Doc from org.apache.avro.io.Decoder.readArrayStart.

Reads and returns the size of the first block of an array. If this method returns non-zero, then the caller should read the indicated number of items, and then call arrayNext to find out the number of items in the next block. The typical pattern for consuming an array looks like:

  for(long i = in.readArrayStart(); i != 0; i = in.arrayNext()) {
    for (long j = 0; j < i; j++) {
      read next element of the array;
    }
  }
Annotations
@Override
readBooleanback to summary
public boolean readBoolean() throws IOException

Implements abstract org.apache.avro.io.Decoder.readBoolean.

Doc from org.apache.avro.io.Decoder.readBoolean.

Reads a boolean value written by Encoder#writeBoolean.

Annotations
@Override
readByteArrayback to summary
private byte[] readByteArray() throws IOException
readBytesback to summary
public ByteBuffer readBytes(ByteBuffer old) throws IOException

Implements abstract org.apache.avro.io.Decoder.readBytes.

Doc from org.apache.avro.io.Decoder.readBytes.

Reads a byte-string written by Encoder#writeBytes. if old is not null and has sufficient capacity to take in the bytes being read, the bytes are returned in old.

Annotations
@Override
readDoubleback to summary
public double readDouble() throws IOException

Implements abstract org.apache.avro.io.Decoder.readDouble.

Doc from org.apache.avro.io.Decoder.readDouble.

Reads a double written by Encoder#writeDouble.

Annotations
@Override
readEnumback to summary
public int readEnum() throws IOException

Implements abstract org.apache.avro.io.Decoder.readEnum.

Doc from org.apache.avro.io.Decoder.readEnum.

Reads an enumeration.

Returns:int

The enumeration's value.

Annotations
@Override
readFixedback to summary
public void readFixed(byte[] bytes, int start, int len) throws IOException

Implements abstract org.apache.avro.io.Decoder.readFixed.

Doc from org.apache.avro.io.Decoder.readFixed.

Reads fixed sized binary object.

Parameters
bytes:byte[]

The buffer to store the contents being read.

start:int

The position where the data needs to be written.

len:int

The size of the binary object.

Annotations
@Override
readFloatback to summary
public float readFloat() throws IOException

Implements abstract org.apache.avro.io.Decoder.readFloat.

Doc from org.apache.avro.io.Decoder.readFloat.

Reads a float written by Encoder#writeFloat.

Annotations
@Override
readIndexback to summary
public int readIndex() throws IOException

Implements abstract org.apache.avro.io.Decoder.readIndex.

Doc from org.apache.avro.io.Decoder.readIndex.

Reads the tag of a union written by Encoder#writeIndex.

Annotations
@Override
readIntback to summary
public int readInt() throws IOException

Implements abstract org.apache.avro.io.Decoder.readInt.

Doc from org.apache.avro.io.Decoder.readInt.

Reads an integer written by Encoder#writeInt.

Annotations
@Override
readLongback to summary
public long readLong() throws IOException

Implements abstract org.apache.avro.io.Decoder.readLong.

Doc from org.apache.avro.io.Decoder.readLong.

Reads a long written by Encoder#writeLong.

Annotations
@Override
readMapStartback to summary
public long readMapStart() throws IOException

Implements abstract org.apache.avro.io.Decoder.readMapStart.

Doc from org.apache.avro.io.Decoder.readMapStart.

Reads and returns the size of the next block of map-entries. Similar to readArrayStart. As an example, let's say you want to read a map of records, the record consisting of an Long field and a Boolean field. Your code would look something like this:

Map m = new HashMap();
Record reuse = new Record();
for (long i = in.readMapStart(); i != 0; i = in.readMapNext()) {
  for (long j = 0; j < i; j++) {
    String key = in.readString();
    reuse.intField = in.readInt();
    reuse.boolField = in.readBoolean();
    m.put(key, reuse);
  }
}
Annotations
@Override
readNullback to summary
public void readNull() throws IOException

Implements abstract org.apache.avro.io.Decoder.readNull.

Doc from org.apache.avro.io.Decoder.readNull.

"Reads" a null value. (Doesn't actually read anything, but advances the state of the parser if the implementation is stateful.)

Annotations
@Override
readStringback to summary
public Utf8 readString(Utf8 old) throws IOException

Implements abstract org.apache.avro.io.Decoder.readString.

Doc from org.apache.avro.io.Decoder.readString.

Reads a char-string written by Encoder#writeString.

Annotations
@Override
readStringback to summary
public String readString() throws IOException

Implements abstract org.apache.avro.io.Decoder.readString.

Doc from org.apache.avro.io.Decoder.readString.

Reads a char-string written by Encoder#writeString.

Annotations
@Override
skipArrayback to summary
public long skipArray() throws IOException

Implements abstract org.apache.avro.io.Decoder.skipArray.

Doc from org.apache.avro.io.Decoder.skipArray.

Used for quickly skipping through an array. Note you can either skip the entire array, or read the entire array (with readArrayStart), but you can't mix the two on the same array. This method will skip through as many items as it can, all of them if possible. It will return zero if there are no more items to skip through, or an item count if it needs the client's help in skipping. The typical usage pattern is:

  for(long i = in.skipArray(); i != 0; i = i.skipArray()) {
    for (long j = 0; j < i; j++) {
      read and discard the next element of the array;
    }
  }
Note that this method can automatically skip through items if a byte-count is found in the underlying data, or if a schema has been provided to the implementation, but otherwise the client will have to skip through items itself.
Annotations
@Override
skipBytesback to summary
public void skipBytes() throws IOException

Implements abstract org.apache.avro.io.Decoder.skipBytes.

Doc from org.apache.avro.io.Decoder.skipBytes.

Discards a byte-string written by Encoder#writeBytes.

Annotations
@Override
skipFixedback to summary
public void skipFixed(int length) throws IOException

Implements abstract org.apache.avro.io.Decoder.skipFixed.

Doc from org.apache.avro.io.Decoder.skipFixed.

Discards fixed sized binary object.

Parameters
length:int

The size of the binary object to be skipped.

Annotations
@Override
skipFixedback to summary
protected void skipFixed() throws IOException

Implements abstract org.apache.avro.io.ParsingDecoder.skipFixed.

Annotations
@Override
skipMapback to summary
public long skipMap() throws IOException

Implements abstract org.apache.avro.io.Decoder.skipMap.

Doc from org.apache.avro.io.Decoder.skipMap.

Support for quickly skipping through a map similar to skipArray. As an example, let's say you want to skip a map of records, the record consisting of an Long field and a Boolean field. Your code would look something like this:

for (long i = in.skipMap(); i != 0; i = in.skipMap()) {
  for (long j = 0; j < i; j++) {
    in.skipString(); // Discard key
    in.readInt(); // Discard int-field of value
    in.readBoolean(); // Discard boolean-field of value
  }
}
Annotations
@Override
skipStringback to summary
public void skipString() throws IOException

Implements abstract org.apache.avro.io.Decoder.skipString.

Doc from org.apache.avro.io.Decoder.skipString.

Discards a char-string written by Encoder#writeString.

Annotations
@Override
org.apache.avro.io back to summary

private Class JsonDecoder.ReorderBuffer

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public JsonParser
public Map<String, TokenBuffer>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

origParserback to summary
public JsonParser origParser
savedFieldsback to summary
public Map<String, TokenBuffer> savedFields

Constructor Detail

ReorderBufferback to summary
private ReorderBuffer()