Skip to content

Commit

Permalink
Continue refactoring to help #400
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 12, 2023
1 parent 0ff5f9f commit 323373d
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 com.fasterxml.jackson.core.*;
import com.fasterxml.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(IOContext ctxt, int parserFeatures, int avroFeatures
_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(IOContext ctxt, int parserFeatures, int avroFeatures,
ObjectCodec codec,
byte[] data, int offset, int len)
byte[] buffer, int offset, int len)
{
super(ctxt, parserFeatures, avroFeatures, codec);
_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 com.fasterxml.jackson.dataformat.avro.apacheimpl;

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

Expand All @@ -16,8 +15,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 @@ -32,18 +29,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 323373d

Please sign in to comment.