Skip to content

Commit

Permalink
Merge branch '2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 12, 2023
2 parents 412acae + 323373d commit 6c4e5e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.Writer;

import org.apache.avro.io.BinaryDecoder;
import org.apache.avro.io.DecoderFactory;

import tools.jackson.core.*;
import tools.jackson.core.io.IOContext;
Expand All @@ -17,6 +18,11 @@
*/
public class ApacheAvroParserImpl extends AvroParserImpl
{
/**
* @since 2.16
*/
protected final static DecoderFactory DECODER_FACTORY = DecoderFactory.get();

/*
/**********************************************************************
/* Input source config
Expand Down Expand Up @@ -74,17 +80,21 @@ public ApacheAvroParserImpl(ObjectReadContext readCtxt, IOContext ioCtxt,
_inputPtr = 0;
_inputEnd = 0;
_bufferRecyclable = true;
_decoder = ApacheCodecRecycler.decoder(in,
Feature.AVRO_BUFFERING.enabledIn(avroFeatures));
final boolean buffering = Feature.AVRO_BUFFERING.enabledIn(avroFeatures);
BinaryDecoder decoderToReuse = ApacheCodecRecycler.acquireDecoder();
_decoder = buffering
? DECODER_FACTORY.binaryDecoder(in, decoderToReuse)
: DECODER_FACTORY.directBinaryDecoder(in, decoderToReuse);
}

public ApacheAvroParserImpl(ObjectReadContext readCtxt, IOContext ioCtxt,
int parserFeatures, int avroFeatures, AvroSchema schema,
byte[] data, int offset, int len)
byte[] buffer, int offset, int len)
{
super(readCtxt, ioCtxt, parserFeatures, avroFeatures, schema);
_inputStream = null;
_decoder = ApacheCodecRecycler.decoder(data, offset, len);
BinaryDecoder decoderToReuse = ApacheCodecRecycler.acquireDecoder();
_decoder = DECODER_FACTORY.binaryDecoder(buffer, offset, len, decoderToReuse);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tools.jackson.dataformat.avro.apacheimpl;

import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -14,8 +13,6 @@
*/
public final class ApacheCodecRecycler
{
protected final static DecoderFactory DECODER_FACTORY = DecoderFactory.get();

protected final static ThreadLocal<SoftReference<ApacheCodecRecycler>> _recycler
= new ThreadLocal<SoftReference<ApacheCodecRecycler>>();

Expand All @@ -30,18 +27,8 @@ private ApacheCodecRecycler() { }
/**********************************************************************
*/

public static BinaryDecoder decoder(InputStream in, boolean buffering)
{
BinaryDecoder prev = _recycler().claimDecoder();
return buffering
? DECODER_FACTORY.binaryDecoder(in, prev)
: DECODER_FACTORY.directBinaryDecoder(in, prev);
}

public static BinaryDecoder decoder(byte[] buffer, int offset, int len)
{
BinaryDecoder prev = _recycler().claimDecoder();
return DECODER_FACTORY.binaryDecoder(buffer, offset, len, prev);
public static BinaryDecoder acquireDecoder() {
return _recycler().claimDecoder();
}

public static BinaryEncoder acquireEncoder() {
Expand Down

0 comments on commit 6c4e5e7

Please sign in to comment.