Package org.apache.avro.io
Class DecoderFactory
java.lang.Object
org.apache.avro.io.DecoderFactory
A factory for creating and configuring
Decoder
s.
Factories are thread-safe, and are generally cached by applications for
performance reasons. Multiple instances are only required if multiple
concurrent configurations are needed.- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbinaryDecoder
(byte[] bytes, int offset, int length, BinaryDecoder reuse) Creates or reinitializes aBinaryDecoder
with the byte array provided as the source of data.binaryDecoder
(byte[] bytes, BinaryDecoder reuse) This method is shorthand forbinaryDecoder
(InputStream in, BinaryDecoder reuse) Creates or reinitializes aBinaryDecoder
with the input stream provided as the source of data.configureDecoderBufferSize
(int size) Configures this factory to use the specified buffer size when creating Decoder instances that buffer their input.createBinaryDecoder
(byte[] bytes, int offset, int length, BinaryDecoder reuse) Deprecated.createBinaryDecoder
(byte[] bytes, BinaryDecoder reuse) Deprecated.usebinaryDecoder(byte[], BinaryDecoder)
insteadcreateBinaryDecoder
(InputStream in, BinaryDecoder reuse) Deprecated.use the equivalentbinaryDecoder(InputStream, BinaryDecoder)
insteadstatic DecoderFactory
Deprecated.use the equivalentget()
insteaddirectBinaryDecoder
(InputStream in, BinaryDecoder reuse) Creates or reinitializes aBinaryDecoder
with the input stream provided as the source of data.static DecoderFactory
get()
Returns an immutable static DecoderFactory configured with default settings All mutating methods throw IllegalArgumentExceptions.int
Returns this factory's configured preferred buffer size.jsonDecoder
(Schema schema, InputStream input) Creates aJsonDecoder
using the InputStream provided for reading data that conforms to the Schema provided.jsonDecoder
(Schema schema, String input) Creates aJsonDecoder
using the String provided for reading data that conforms to the Schema provided.resolvingDecoder
(Schema writer, Schema reader, Decoder wrapped) Creates aResolvingDecoder
wrapping the Decoder provided.validatingDecoder
(Schema schema, Decoder wrapped) Creates aValidatingDecoder
wrapping the Decoder provided.
-
Constructor Details
-
DecoderFactory
public DecoderFactory()Constructor for factory instances
-
-
Method Details
-
defaultFactory
Deprecated.use the equivalentget()
instead -
get
Returns an immutable static DecoderFactory configured with default settings All mutating methods throw IllegalArgumentExceptions. All creator methods create objects with default settings. -
configureDecoderBufferSize
Configures this factory to use the specified buffer size when creating Decoder instances that buffer their input. The default buffer size is 8192 bytes.- Parameters:
size
- The preferred buffer size. Valid values are in the range [32, 16*1024*1024]. Values outside this range are rounded to the nearest value in the range. Values less than 512 or greater than 1024*1024 are not recommended.- Returns:
- This factory, to enable method chaining:
DecoderFactory myFactory = new DecoderFactory().useBinaryDecoderBufferSize(4096);
-
getConfiguredBufferSize
public int getConfiguredBufferSize()Returns this factory's configured preferred buffer size. Used when creating Decoder instances that buffer. SeeconfigureDecoderBufferSize(int)
- Returns:
- The preferred buffer size, in bytes.
-
createBinaryDecoder
Deprecated.use the equivalentbinaryDecoder(InputStream, BinaryDecoder)
instead -
binaryDecoder
Creates or reinitializes aBinaryDecoder
with the input stream provided as the source of data. If reuse is provided, it will be reinitialized to the given input stream.BinaryDecoder
instances returned by this method buffer their input, reading up togetConfiguredBufferSize()
bytes past the minimum required to satisfy read requests in order to achieve better performance. If the buffering is not desired, usedirectBinaryDecoder(InputStream, BinaryDecoder)
.BinaryDecoder.inputStream()
provides a view on the data that is buffer-aware, for users that need to interleave access to data with the Decoder API.- Parameters:
in
- The InputStream to initialize toreuse
- The BinaryDecoder to attempt to reuse given the factory configuration. A BinaryDecoder implementation may not be compatible with reuse, causing a new instance to be returned. If null, a new instance is returned.- Returns:
- A BinaryDecoder that uses in as its source of data. If reuse is null, this will be a new instance. If reuse is not null, then it may be reinitialized if compatible, otherwise a new instance will be returned.
- See Also:
-
directBinaryDecoder
Creates or reinitializes aBinaryDecoder
with the input stream provided as the source of data. If reuse is provided, it will be reinitialized to the given input stream.BinaryDecoder
instances returned by this method do not buffer their input. In most cases a buffering BinaryDecoder is sufficient in combination withBinaryDecoder.inputStream()
which provides a buffer-aware view on the data. A "direct" BinaryDecoder does not read ahead from an InputStream or other data source that cannot be rewound. From the perspective of a client, a "direct" decoder must never read beyond the minimum necessary bytes to service aBinaryDecoder
API read request. In the case that the improved performance of a buffering implementation does not outweigh the inconvenience of its buffering semantics, a "direct" decoder can be used.- Parameters:
in
- The InputStream to initialize toreuse
- The BinaryDecoder to attempt to reuse given the factory configuration. A BinaryDecoder implementation may not be compatible with reuse, causing a new instance to be returned. If null, a new instance is returned.- Returns:
- A BinaryDecoder that uses in as its source of data. If reuse is null, this will be a new instance. If reuse is not null, then it may be reinitialized if compatible, otherwise a new instance will be returned.
- See Also:
-
createBinaryDecoder
@Deprecated public BinaryDecoder createBinaryDecoder(byte[] bytes, int offset, int length, BinaryDecoder reuse) Deprecated.usebinaryDecoder(byte[], int, int, BinaryDecoder)
instead -
binaryDecoder
Creates or reinitializes aBinaryDecoder
with the byte array provided as the source of data. If reuse is provided, it will attempt to reinitialize reuse to the new byte array. This instance will use the provided byte array as its buffer.BinaryDecoder.inputStream()
provides a view on the data that is buffer-aware and can provide a view of the data not yet read by Decoder API methods.- Parameters:
bytes
- The byte array to initialize tooffset
- The offset to start reading fromlength
- The maximum number of bytes to read from the byte arrayreuse
- The BinaryDecoder to attempt to reinitialize. if null a new BinaryDecoder is created.- Returns:
- A BinaryDecoder that uses bytes as its source of data. If reuse is null, this will be a new instance. reuse may be reinitialized if appropriate, otherwise a new instance is returned. Clients must not assume that reuse is reinitialized and returned.
-
createBinaryDecoder
Deprecated.usebinaryDecoder(byte[], BinaryDecoder)
instead -
binaryDecoder
This method is shorthand forcreateBinaryDecoder(bytes, 0, bytes.length, reuse);
binaryDecoder(byte[], int, int, BinaryDecoder)
-
jsonDecoder
Creates aJsonDecoder
using the InputStream provided for reading data that conforms to the Schema provided.- Parameters:
schema
- The Schema for data read from this JsonEncoder. Cannot be null.input
- The InputStream to read from. Cannot be null.- Returns:
- A JsonEncoder configured with input and schema
- Throws:
IOException
-
jsonDecoder
Creates aJsonDecoder
using the String provided for reading data that conforms to the Schema provided.- Parameters:
schema
- The Schema for data read from this JsonEncoder. Cannot be null.input
- The String to read from. Cannot be null.- Returns:
- A JsonEncoder configured with input and schema
- Throws:
IOException
-
validatingDecoder
Creates aValidatingDecoder
wrapping the Decoder provided. This ValidatingDecoder will ensure that operations against it conform to the schema provided.- Parameters:
schema
- The Schema to validate against. Cannot be null.wrapped
- The Decoder to wrap.- Returns:
- A ValidatingDecoder configured with wrapped and schema
- Throws:
IOException
-
resolvingDecoder
public ResolvingDecoder resolvingDecoder(Schema writer, Schema reader, Decoder wrapped) throws IOException Creates aResolvingDecoder
wrapping the Decoder provided. This ResolvingDecoder will resolve input conforming to the writer schema from the wrapped Decoder, and present it as the reader schema.- Parameters:
writer
- The Schema that the source data is in. Cannot be null.reader
- The Schema that the reader wishes to read the data as. Cannot be null.wrapped
- The Decoder to wrap.- Returns:
- A ResolvingDecoder configured to resolve writer to reader from in
- Throws:
IOException
-
binaryDecoder(byte[], int, int, BinaryDecoder)
instead