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

public Class DecoderFactory

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.avro.io.DecoderFactory.DefaultDecoderFactory
Imports
java.io.IOException, .InputStream, org.apache.avro.Schema

A factory for creating and configuring Decoders.

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
Decoder

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv static final int
private static final DecoderFactory

Constructor Summary

AccessConstructor and Description
public
DecoderFactory()

Constructor for factory instances

Method Summary

Modifier and TypeMethod and Description
public BinaryDecoder

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.
binaryDecoder
(InputStream
The InputStream to initialize to
in
,
BinaryDecoder
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.
reuse
)

Creates or reinitializes a BinaryDecoder with the input stream provided as the source of data.

public BinaryDecoder

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.
binaryDecoder
(byte[]
The byte array to initialize to
bytes
,
int
The offset to start reading from
offset
,
int
The maximum number of bytes to read from the byte array
length
,
BinaryDecoder
The BinaryDecoder to attempt to reinitialize. if null a new BinaryDecoder is created.
reuse
)

Creates or reinitializes a BinaryDecoder with the byte array provided as the source of data.

public BinaryDecoder
binaryDecoder(byte[] bytes, BinaryDecoder reuse)

This method is shorthand for

createBinaryDecoder(bytes, 0, bytes.length, reuse);
public DecoderFactory

Returns:

This factory, to enable method chaining:
        DecoderFactory myFactory = new DecoderFactory().useBinaryDecoderBufferSize(4096);
        
configureDecoderBufferSize
(int
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.
size
)

Configures this factory to use the specified buffer size when creating Decoder instances that buffer their input.

public BinaryDecoder
public BinaryDecoder
createBinaryDecoder(byte[] bytes, int offset, int length, BinaryDecoder reuse)

public BinaryDecoder
createBinaryDecoder(byte[] bytes, BinaryDecoder reuse)

Deprecated use binaryDecoder(byte[], BinaryDecoder) instead
public static DecoderFactory
defaultFactory()

Deprecated use the equivalent get() instead
public BinaryDecoder

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.
directBinaryDecoder
(InputStream
The InputStream to initialize to
in
,
BinaryDecoder
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.
reuse
)

Creates or reinitializes a BinaryDecoder with the input stream provided as the source of data.

public static DecoderFactory
get()

Returns an immutable static DecoderFactory configured with default settings All mutating methods throw IllegalArgumentExceptions.

public int

Returns:

The preferred buffer size, in bytes.
getConfiguredBufferSize
()

Returns this factory's configured preferred buffer size.

public JsonDecoder

Returns:

A JsonEncoder configured with input and schema
jsonDecoder
(Schema
The Schema for data read from this JsonEncoder. Cannot be null.
schema
,
InputStream
The InputStream to read from. Cannot be null.
input
)

Creates a JsonDecoder using the InputStream provided for reading data that conforms to the Schema provided.

public JsonDecoder

Returns:

A JsonEncoder configured with input and schema
jsonDecoder
(Schema
The Schema for data read from this JsonEncoder. Cannot be null.
schema
,
String
The String to read from. Cannot be null.
input
)

Creates a JsonDecoder using the String provided for reading data that conforms to the Schema provided.

public ResolvingDecoder

Returns:

A ResolvingDecoder configured to resolve writer to reader from in
resolvingDecoder
(Schema
The Schema that the source data is in. Cannot be null.
writer
,
Schema
The Schema that the reader wishes to read the data as. Cannot be null.
reader
,
Decoder
The Decoder to wrap.
wrapped
)

Creates a ResolvingDecoder wrapping the Decoder provided.

public ValidatingDecoder

Returns:

A ValidatingDecoder configured with wrapped and schema
validatingDecoder
(Schema
The Schema to validate against. Cannot be null.
schema
,
Decoder
The Decoder to wrap.
wrapped
)

Creates a ValidatingDecoder wrapping the Decoder provided.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

binaryDecoderBufferSizeback to summary
pack-priv int binaryDecoderBufferSize
DEFAULT_BUFFER_SIZEback to summary
pack-priv static final int DEFAULT_BUFFER_SIZE
DEFAULT_FACTORYback to summary
private static final DecoderFactory DEFAULT_FACTORY

Constructor Detail

DecoderFactoryback to summary
public DecoderFactory()

Constructor for factory instances

Method Detail

binaryDecoderback to summary
public BinaryDecoder binaryDecoder(InputStream in, BinaryDecoder reuse)

Creates or reinitializes a BinaryDecoder 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 to getConfiguredBufferSize() bytes past the minimum required to satisfy read requests in order to achieve better performance. If the buffering is not desired, use directBinaryDecoder(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:InputStream

The InputStream to initialize to

reuse:BinaryDecoder

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:BinaryDecoder

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
BinaryDecoder, Decoder
binaryDecoderback to summary
public BinaryDecoder binaryDecoder(byte[] bytes, int offset, int length, BinaryDecoder reuse)

Creates or reinitializes a BinaryDecoder 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:byte[]

The byte array to initialize to

offset:int

The offset to start reading from

length:int

The maximum number of bytes to read from the byte array

reuse:BinaryDecoder

The BinaryDecoder to attempt to reinitialize. if null a new BinaryDecoder is created.

Returns:BinaryDecoder

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.

binaryDecoderback to summary
public BinaryDecoder binaryDecoder(byte[] bytes, BinaryDecoder reuse)

This method is shorthand for

createBinaryDecoder(bytes, 0, bytes.length, reuse);
binaryDecoder(byte[], int, int, BinaryDecoder)
configureDecoderBufferSizeback to summary
public DecoderFactory configureDecoderBufferSize(int size)

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:int

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:DecoderFactory

This factory, to enable method chaining:

        DecoderFactory myFactory = new DecoderFactory().useBinaryDecoderBufferSize(4096);
        
createBinaryDecoderback to summary
public BinaryDecoder createBinaryDecoder(InputStream in, BinaryDecoder reuse)

Deprecated

use the equivalent binaryDecoder(InputStream, BinaryDecoder) instead

Annotations
@Deprecated
createBinaryDecoderback to summary
public BinaryDecoder createBinaryDecoder(byte[] bytes, int offset, int length, BinaryDecoder reuse)
Annotations
@Deprecated
createBinaryDecoderback to summary
public BinaryDecoder createBinaryDecoder(byte[] bytes, BinaryDecoder reuse)

Deprecated

use binaryDecoder(byte[], BinaryDecoder) instead

Annotations
@Deprecated
defaultFactoryback to summary
public static DecoderFactory defaultFactory()

Deprecated

use the equivalent get() instead

Annotations
@Deprecated
directBinaryDecoderback to summary
public BinaryDecoder directBinaryDecoder(InputStream in, BinaryDecoder reuse)

Creates or reinitializes a BinaryDecoder 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 with BinaryDecoder#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 a BinaryDecoder 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:InputStream

The InputStream to initialize to

reuse:BinaryDecoder

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:BinaryDecoder

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, Decoder
getback to summary
public static DecoderFactory get()

Returns an immutable static DecoderFactory configured with default settings All mutating methods throw IllegalArgumentExceptions. All creator methods create objects with default settings.

getConfiguredBufferSizeback to summary
public int getConfiguredBufferSize()

Returns this factory's configured preferred buffer size. Used when creating Decoder instances that buffer. See configureDecoderBufferSize

Returns:int

The preferred buffer size, in bytes.

jsonDecoderback to summary
public JsonDecoder jsonDecoder(Schema schema, InputStream input) throws IOException

Creates a JsonDecoder using the InputStream provided for reading data that conforms to the Schema provided.

Parameters
schema:Schema

The Schema for data read from this JsonEncoder. Cannot be null.

input:InputStream

The InputStream to read from. Cannot be null.

Returns:JsonDecoder

A JsonEncoder configured with input and schema

jsonDecoderback to summary
public JsonDecoder jsonDecoder(Schema schema, String input) throws IOException

Creates a JsonDecoder using the String provided for reading data that conforms to the Schema provided.

Parameters
schema:Schema

The Schema for data read from this JsonEncoder. Cannot be null.

input:String

The String to read from. Cannot be null.

Returns:JsonDecoder

A JsonEncoder configured with input and schema

resolvingDecoderback to summary
public ResolvingDecoder resolvingDecoder(Schema writer, Schema reader, Decoder wrapped) throws IOException

Creates a ResolvingDecoder 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:Schema

The Schema that the source data is in. Cannot be null.

reader:Schema

The Schema that the reader wishes to read the data as. Cannot be null.

wrapped:Decoder

The Decoder to wrap.

Returns:ResolvingDecoder

A ResolvingDecoder configured to resolve writer to reader from in

validatingDecoderback to summary
public ValidatingDecoder validatingDecoder(Schema schema, Decoder wrapped) throws IOException

Creates a ValidatingDecoder wrapping the Decoder provided. This ValidatingDecoder will ensure that operations against it conform to the schema provided.

Parameters
schema:Schema

The Schema to validate against. Cannot be null.

wrapped:Decoder

The Decoder to wrap.

Returns:ValidatingDecoder

A ValidatingDecoder configured with wrapped and schema

org.apache.avro.io back to summary

private Class DecoderFactory.DefaultDecoderFactory

extends DecoderFactory
Class Inheritance

Field Summary

Inherited from org.apache.avro.io.DecoderFactory:
binaryDecoderBufferSizeDEFAULT_BUFFER_SIZE

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public DecoderFactory
configureDecoderBufferSize(int
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.
bufferSize
)

Overrides org.apache.avro.io.DecoderFactory.configureDecoderBufferSize.

Configures this factory to use the specified buffer size when creating Decoder instances that buffer their input.
Inherited from org.apache.avro.io.DecoderFactory:
binaryDecoderbinaryDecoderbinaryDecodercreateBinaryDecodercreateBinaryDecodercreateBinaryDecoderdefaultFactorydirectBinaryDecodergetgetConfiguredBufferSizejsonDecoderjsonDecoderresolvingDecodervalidatingDecoder

Constructor Detail

DefaultDecoderFactoryback to summary
private DefaultDecoderFactory()

Method Detail

configureDecoderBufferSizeback to summary
public DecoderFactory configureDecoderBufferSize(int bufferSize)

Overrides org.apache.avro.io.DecoderFactory.configureDecoderBufferSize.

Doc from org.apache.avro.io.DecoderFactory.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
bufferSize:int

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:DecoderFactory

This factory, to enable method chaining:

        DecoderFactory myFactory = new DecoderFactory().useBinaryDecoderBufferSize(4096);
        
Annotations
@Override