Package org.apache.avro.io
Class JsonEncoder
java.lang.Object
org.apache.avro.io.Encoder
org.apache.avro.io.ParsingEncoder
org.apache.avro.io.JsonEncoder
- All Implemented Interfaces:
- Flushable,- Parser.ActionHandler
An 
Encoder for Avro's JSON data encoding.
 
 Construct using EncoderFactory.
 
 JsonEncoder buffers output, and data may not appear on the output until
 Flushable.flush() is called.
 
 JsonEncoder is not thread-safe.- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected BitSetHas anything been written into the collections?Fields inherited from class org.apache.avro.io.ParsingEncoderpos
- 
Method SummaryModifier and TypeMethodDescriptionconfigure(OutputStream out) Reconfigures this JsonEncoder to use the output stream provided.configure(OutputStream out, boolean autoflush) Reconfigures this JsonEncoder to use the output stream provided.Handle the action symbol top when the input is sought to be taken off the stack.voidflush()booleanvoidsetIncludeNamespace(boolean includeNamespace) voidStart a new item of an array or map.voidCall this method to finish writing an array.voidCall this method to start writing an array.voidwriteBoolean(boolean b) Write a boolean value.voidwriteBytes(byte[] bytes, int start, int len) Write a byte string.voidwriteBytes(ByteBuffer bytes) Write a byte string.voidwriteDouble(double d) Write a double.voidwriteEnum(int e) Writes an enumeration.voidwriteFixed(byte[] bytes, int start, int len) Writes a fixed size binary object.voidwriteFloat(float f) Write a float.voidwriteIndex(int unionIndex) Call this method to write the tag of a union.voidwriteInt(int n) Writes a 32-bit integer.voidwriteLong(long n) Write a 64-bit integer.voidCall this method to terminate the inner-most, currently-opened map.voidCall this to start a new map.void"Writes" a null value.voidwriteString(String str) Write a Unicode character string.voidwriteString(Utf8 utf8) Write a Unicode character string.Methods inherited from class org.apache.avro.io.ParsingEncoderdepth, pop, push, setItemCountMethods inherited from class org.apache.avro.io.EncoderwriteBytes, writeFixed, writeFixed, writeString
- 
Field Details- 
isEmptyHas anything been written into the collections?
 
- 
- 
Method Details- 
flush- Specified by:
- flushin interface- Flushable
- Throws:
- IOException
 
- 
isIncludeNamespacepublic boolean isIncludeNamespace()
- 
setIncludeNamespacepublic void setIncludeNamespace(boolean includeNamespace) 
- 
configureReconfigures this JsonEncoder to use the output stream provided. If the OutputStream provided is null, a NullPointerException is thrown. Otherwise, this JsonEncoder will flush its current output and then reconfigure its output to use a default UTF8 JsonGenerator that writes to the provided OutputStream.- Parameters:
- out- The OutputStream to direct output to. Cannot be null.
- Returns:
- this JsonEncoder
- Throws:
- IOException
- NullPointerException- if- outis- null
 
- 
configureReconfigures this JsonEncoder to use the output stream provided. If the OutputStream provided is null, a NullPointerException is thrown. Otherwise, this JsonEncoder will flush its current output and then reconfigure its output to use a default UTF8 JsonGenerator that writes to the provided OutputStream.- Parameters:
- out- The OutputStream to direct output to. Cannot be null.
- Returns:
- this JsonEncoder
- Throws:
- IOException
- NullPointerException- if- outis- null
 
- 
writeNullDescription copied from class:Encoder"Writes" a null value. (Doesn't actually write anything, but advances the state of the parser if this class is stateful.)- Specified by:
- writeNullin class- Encoder
- Throws:
- IOException
 
- 
writeBooleanDescription copied from class:EncoderWrite a boolean value.- Specified by:
- writeBooleanin class- Encoder
- Throws:
- IOException
 
- 
writeIntDescription copied from class:EncoderWrites a 32-bit integer.- Specified by:
- writeIntin class- Encoder
- Throws:
- IOException
 
- 
writeLongDescription copied from class:EncoderWrite a 64-bit integer.- Specified by:
- writeLongin class- Encoder
- Throws:
- IOException
 
- 
writeFloatDescription copied from class:EncoderWrite a float.- Specified by:
- writeFloatin class- Encoder
- Throws:
- IOException
 
- 
writeDoubleDescription copied from class:EncoderWrite a double.- Specified by:
- writeDoublein class- Encoder
- Throws:
- IOException
 
- 
writeStringDescription copied from class:EncoderWrite a Unicode character string.- Specified by:
- writeStringin class- Encoder
- Throws:
- IOException
 
- 
writeStringDescription copied from class:EncoderWrite a Unicode character string. The default implementation converts the String to aUtf8. Some Encoder implementations may want to do something different as a performance optimization.- Overrides:
- writeStringin class- Encoder
- Throws:
- IOException
 
- 
writeBytesDescription copied from class:EncoderWrite a byte string.- Specified by:
- writeBytesin class- Encoder
- Throws:
- IOException
 
- 
writeBytesDescription copied from class:EncoderWrite a byte string.- Specified by:
- writeBytesin class- Encoder
- Throws:
- IOException
 
- 
writeFixedDescription copied from class:EncoderWrites a fixed size binary object.- Specified by:
- writeFixedin class- Encoder
- Parameters:
- bytes- The contents to write
- start- The position within bytes where the contents start.
- len- The number of bytes to write.
- Throws:
- IOException
 
- 
writeEnumDescription copied from class:EncoderWrites an enumeration.- Specified by:
- writeEnumin class- Encoder
- Parameters:
- e- the enumeration to write
- Throws:
- IOException
 
- 
writeArrayStartDescription copied from class:EncoderCall this method to start writing an array. When starting to serialize an array, callEncoder.writeArrayStart(). Then, before writing any data for any item callEncoder.setItemCount(long)followed by a sequence ofEncoder.startItem()and the item itself. The number ofEncoder.startItem()should match the number specified inEncoder.setItemCount(long). When actually writing the data of the item, you can call anyEncodermethod (e.g.,Encoder.writeLong(long)). When all items of the array have been written, callEncoder.writeArrayEnd(). As an example, let's say you want to write an array of records, the record consisting of a 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();- Specified by:
- writeArrayStartin class- Encoder
- Throws:
- IOException
 
- 
writeArrayEndDescription copied from class:EncoderCall this method to finish writing an array. SeeEncoder.writeArrayStart()for usage information.- Specified by:
- writeArrayEndin class- Encoder
- Throws:
- IOException
 
- 
writeMapStartDescription copied from class:EncoderCall this to start a new map. SeeEncoder.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 a Long field and a Boolean field. Your code would look something like this:out.writeMapStart(); out.setItemCount(list.size()); for (Map.Entryinvalid input: '<'String, Record> entry : map.entrySet()) { out.startItem(); out.writeString(entry.getKey()); out.writeLong(entry.getValue().longField); out.writeBoolean(entry.getValue().boolField); } out.writeMapEnd();- Specified by:
- writeMapStartin class- Encoder
- Throws:
- IOException
 
- 
writeMapEndDescription copied from class:EncoderCall this method to terminate the inner-most, currently-opened map. SeeEncoder.writeArrayStart()for more details.- Specified by:
- writeMapEndin class- Encoder
- Throws:
- IOException
 
- 
startItemDescription copied from class:EncoderStart a new item of an array or map. SeeEncoder.writeArrayStart()for usage information.- Overrides:
- startItemin class- ParsingEncoder
- Throws:
- IOException
 
- 
writeIndexDescription copied from class:EncoderCall this method to write the tag of a union. As an example of usage, let's say you want to write a union, whose second branch is a record consisting of a Long field and a Boolean field. Your code would look something like this:out.writeIndex(1); out.writeLong(record.longField); out.writeBoolean(record.boolField); - Specified by:
- writeIndexin class- Encoder
- Throws:
- IOException
 
- 
doActionDescription copied from interface:Parser.ActionHandlerHandle the action symbol top when the input is sought to be taken off the stack.- Specified by:
- doActionin interface- Parser.ActionHandler
- Parameters:
- input- The input symbol from the caller of advance
- top- The symbol at the top the stack.
- Returns:
- null if advance() is to continue processing the stack. If not null the return value will be returned by advance().
- Throws:
- IOException
 
 
-