|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.avro.io.DecoderFactory
public class DecoderFactory
A factory for creating and configuring Decoder
s.
Decoder
Constructor Summary | |
---|---|
DecoderFactory()
Constructor for factory instances |
Method Summary | |
---|---|
DecoderFactory |
configureDecoderBufferSize(int size)
Configures this factory to use the specified buffer size when creating Decoder instances that buffer their input. |
DecoderFactory |
configureDirectDecoder(boolean useDirect)
Configures this factory to create "direct" BinaryDecoder instances when applicable. |
BinaryDecoder |
createBinaryDecoder(byte[] bytes,
BinaryDecoder reuse)
This method is shorthand for |
BinaryDecoder |
createBinaryDecoder(byte[] bytes,
int offset,
int length,
BinaryDecoder reuse)
Creates or reinitializes a BinaryDecoder with the byte array
provided as the source of data. |
BinaryDecoder |
createBinaryDecoder(InputStream in,
BinaryDecoder reuse)
Creates or reinitializes a BinaryDecoder with the input stream
provided as the source of data. |
static DecoderFactory |
defaultFactory()
Returns an immutable static DecoderFactory configured with default settings All mutating methods throw IllegalArgumentExceptions. |
int |
getConfiguredBufferSize()
Returns this factory's configured preferred buffer size. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DecoderFactory()
Method Detail |
---|
public static DecoderFactory defaultFactory()
public DecoderFactory configureDecoderBufferSize(int size)
size
- The preferred buffer size. Valid values are in the range [32,
16*1024*1024]. Values outide this range are rounded to the nearest
value in the range. Values less than 512 or greater than 1024*1024
are not recommended.
DecoderFactory myFactory = new DecoderFactory().useBinaryDecoderBufferSize(4096);
public int getConfiguredBufferSize()
configureDecoderBufferSize(int)
public DecoderFactory configureDirectDecoder(boolean useDirect)
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 performance of a normal BinaryDecoder does not outweigh the
inconvenience of its buffering semantics, a "direct" decoder can be
used.
Generally, this distinction only applies to BinaryDecoder that read from an InputStream.
useDirect
- If true, this factory will generate "direct" BinaryDecoder
implementations when applicable. If false (the default) the faster buffering
implementations will be generated.
DecoderFactory myFactory = new DecoderFactory().configureDirectDecoder(true);
public BinaryDecoder createBinaryDecoder(InputStream in, BinaryDecoder reuse)
BinaryDecoder
with the input stream
provided as the source of data. If reuse is provided, it will be
reinitialized to the given input stream.
If this factory is configured to create "direct" BinaryDecoder instances,
this will return a non-buffering variant. Otherwise, this instance will
buffer the number of bytes configured by this factory, reading up to that
many bytes from the InputStream ahead of the minimum required for Decoder
API requests. BinaryDecoder.inputStream()
provides a view on the data
that is buffer-aware, for users that need to access possibly buffered data
outside of the Decoder API.
in
- The InputStream to initialize toreuse
- The BinaryDecoder to attempt to reuse given the factory
configuration. A specific BinaryDecoder implementation may not be
compatible with reuse. For example, a BinaryDecoder created as
'direct' can not be reinitialized to function in a non-'direct'
mode. If reuse is null a new instance is always created.
DecoderFactory factory = new DecoderFactory(); Decoder d = factory.createBinaryDecoder(input, null); // a new BinaryDecoder d = createBinaryDecoder(input2, d); // reinitializes d to read from input2 factory.configureDirectDecoder(true); Decoder d2 = factory.createBinaryDecoder(input3, d); // a new BinaryDecoderd2 above is not a reused instance of d because the latter is not 'direct' and can't be reused to create a 'direct' instance. Users must be careful to use the BinaryDecoder returned from the factory and not assume that the factory passed in the reuse argument
public BinaryDecoder createBinaryDecoder(byte[] bytes, int offset, int length, BinaryDecoder reuse)
BinaryDecoder
with the byte array
provided as the source of data. If reuse is provided, it will
attempt to reinitiailize 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.
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.
public BinaryDecoder createBinaryDecoder(byte[] bytes, BinaryDecoder reuse)
createBinaryDecoder(bytes, 0, bytes.length, reuse);
createBinaryDecoder(byte[], int, int, BinaryDecoder)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |