Package org.apache.avro.io
Class ValidatingEncoder
java.lang.Object
org.apache.avro.io.Encoder
org.apache.avro.io.ParsingEncoder
org.apache.avro.io.ValidatingEncoder
- All Implemented Interfaces:
Flushable,Parser.ActionHandler
An implementation of
Encoder that wraps another Encoder and ensures
that the sequence of operations conforms to the provided schema.
Use EncoderFactory.validatingEncoder(Schema, Encoder) to construct
and configure.
ValidatingEncoder is not thread-safe.- See Also:
-
Field Summary
FieldsFields inherited from class org.apache.avro.io.ParsingEncoder
pos -
Method Summary
Modifier and TypeMethodDescriptionReconfigures this ValidatingEncoder to wrap the encoder provided.Handle the action symbol top when the input is sought to be taken off the stack.voidflush()voidsetItemCount(long itemCount) Call this method before writing a batch of items in an array or a map.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(CharSequence charSequence) Write a Unicode character string.voidwriteString(String str) Write a Unicode character string.voidwriteString(Utf8 utf8) Write a Unicode character string.Methods inherited from class org.apache.avro.io.ParsingEncoder
depth, pop, pushMethods inherited from class org.apache.avro.io.Encoder
writeBytes, writeFixed, writeFixed
-
Field Details
-
out
-
parser
-
-
Method Details
-
flush
- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
configure
Reconfigures this ValidatingEncoder to wrap the encoder provided.- Parameters:
encoder- The Encoder to wrap for validation.- Returns:
- This ValidatingEncoder.
-
writeNull
Description 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 classEncoder- Throws:
IOException
-
writeBoolean
Description copied from class:EncoderWrite a boolean value.- Specified by:
writeBooleanin classEncoder- Throws:
IOException
-
writeInt
Description copied from class:EncoderWrites a 32-bit integer.- Specified by:
writeIntin classEncoder- Throws:
IOException
-
writeLong
Description copied from class:EncoderWrite a 64-bit integer.- Specified by:
writeLongin classEncoder- Throws:
IOException
-
writeFloat
Description copied from class:EncoderWrite a float.- Specified by:
writeFloatin classEncoder- Throws:
IOException
-
writeDouble
Description copied from class:EncoderWrite a double.- Specified by:
writeDoublein classEncoder- Throws:
IOException
-
writeString
Description copied from class:EncoderWrite a Unicode character string.- Specified by:
writeStringin classEncoder- Throws:
IOException
-
writeString
Description 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 classEncoder- Throws:
IOException
-
writeString
Description copied from class:EncoderWrite a Unicode character string. If the CharSequence is anUtf8it writes this directly, otherwise the CharSequence is converted to a String via toString() and written.- Overrides:
writeStringin classEncoder- Throws:
IOException
-
writeBytes
Description copied from class:EncoderWrite a byte string.- Specified by:
writeBytesin classEncoder- Throws:
IOException
-
writeBytes
Description copied from class:EncoderWrite a byte string.- Specified by:
writeBytesin classEncoder- Throws:
IOException
-
writeFixed
Description copied from class:EncoderWrites a fixed size binary object.- Specified by:
writeFixedin classEncoder- Parameters:
bytes- The contents to writestart- The position within bytes where the contents start.len- The number of bytes to write.- Throws:
IOException
-
writeEnum
Description copied from class:EncoderWrites an enumeration.- Specified by:
writeEnumin classEncoder- Parameters:
e-- Throws:
IOException
-
writeArrayStart
Description 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 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();- Specified by:
writeArrayStartin classEncoder- Throws:
IOException
-
writeArrayEnd
Description copied from class:EncoderCall this method to finish writing an array. SeeEncoder.writeArrayStart()for usage information.- Specified by:
writeArrayEndin classEncoder- Throws:
IOException
-
writeMapStart
Description 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 an 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 classEncoder- Throws:
IOException
-
writeMapEnd
Description copied from class:EncoderCall this method to terminate the inner-most, currently-opened map. SeeEncoder.writeArrayStart()for more details.- Specified by:
writeMapEndin classEncoder- Throws:
IOException
-
setItemCount
Description copied from class:EncoderCall this method before writing a batch of items in an array or a map. Then for each item, callEncoder.startItem()followed by any of the other write methods ofEncoder. The number of calls toEncoder.startItem()must be equal to the count specified inEncoder.setItemCount(long). Once a batch is completed you can start another batch withEncoder.setItemCount(long).- Overrides:
setItemCountin classParsingEncoder- Parameters:
itemCount- The number ofEncoder.startItem()calls to follow.- Throws:
IOException
-
startItem
Description copied from class:EncoderStart a new item of an array or map. SeeEncoder.writeArrayStart()for usage information.- Overrides:
startItemin classParsingEncoder- Throws:
IOException
-
writeIndex
Description 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 an 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 classEncoder- Throws:
IOException
-
doAction
Description copied from interface:Parser.ActionHandlerHandle the action symbol top when the input is sought to be taken off the stack.- Specified by:
doActionin interfaceParser.ActionHandler- Parameters:
input- The input symbol from the caller of advancetop- 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
-