Skip to content

Commit 323373d

Browse files
committed
Continue refactoring to help #400
1 parent 0ff5f9f commit 323373d

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/apacheimpl/ApacheAvroParserImpl.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.Writer;
66

77
import org.apache.avro.io.BinaryDecoder;
8+
import org.apache.avro.io.DecoderFactory;
89

910
import com.fasterxml.jackson.core.*;
1011
import com.fasterxml.jackson.core.io.IOContext;
@@ -17,6 +18,11 @@
1718
*/
1819
public class ApacheAvroParserImpl extends AvroParserImpl
1920
{
21+
/**
22+
* @since 2.16
23+
*/
24+
protected final static DecoderFactory DECODER_FACTORY = DecoderFactory.get();
25+
2026
/*
2127
/**********************************************************
2228
/* Input source config
@@ -74,17 +80,21 @@ public ApacheAvroParserImpl(IOContext ctxt, int parserFeatures, int avroFeatures
7480
_inputEnd = 0;
7581
_bufferRecyclable = true;
7682

77-
_decoder = ApacheCodecRecycler.decoder(in,
78-
Feature.AVRO_BUFFERING.enabledIn(avroFeatures));
83+
final boolean buffering = Feature.AVRO_BUFFERING.enabledIn(avroFeatures);
84+
BinaryDecoder decoderToReuse = ApacheCodecRecycler.acquireDecoder();
85+
_decoder = buffering
86+
? DECODER_FACTORY.binaryDecoder(in, decoderToReuse)
87+
: DECODER_FACTORY.directBinaryDecoder(in, decoderToReuse);
7988
}
8089

8190
public ApacheAvroParserImpl(IOContext ctxt, int parserFeatures, int avroFeatures,
8291
ObjectCodec codec,
83-
byte[] data, int offset, int len)
92+
byte[] buffer, int offset, int len)
8493
{
8594
super(ctxt, parserFeatures, avroFeatures, codec);
8695
_inputStream = null;
87-
_decoder = ApacheCodecRecycler.decoder(data, offset, len);
96+
BinaryDecoder decoderToReuse = ApacheCodecRecycler.acquireDecoder();
97+
_decoder = DECODER_FACTORY.binaryDecoder(buffer, offset, len, decoderToReuse);
8898
}
8999

90100
@Override

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/apacheimpl/ApacheCodecRecycler.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.fasterxml.jackson.dataformat.avro.apacheimpl;
22

3-
import java.io.InputStream;
43
import java.lang.ref.SoftReference;
54
import java.util.concurrent.atomic.AtomicReference;
65

@@ -16,8 +15,6 @@
1615
*/
1716
public final class ApacheCodecRecycler
1817
{
19-
protected final static DecoderFactory DECODER_FACTORY = DecoderFactory.get();
20-
2118
protected final static ThreadLocal<SoftReference<ApacheCodecRecycler>> _recycler
2219
= new ThreadLocal<SoftReference<ApacheCodecRecycler>>();
2320

@@ -32,18 +29,8 @@ private ApacheCodecRecycler() { }
3229
/**********************************************************
3330
*/
3431

35-
public static BinaryDecoder decoder(InputStream in, boolean buffering)
36-
{
37-
BinaryDecoder prev = _recycler().claimDecoder();
38-
return buffering
39-
? DECODER_FACTORY.binaryDecoder(in, prev)
40-
: DECODER_FACTORY.directBinaryDecoder(in, prev);
41-
}
42-
43-
public static BinaryDecoder decoder(byte[] buffer, int offset, int len)
44-
{
45-
BinaryDecoder prev = _recycler().claimDecoder();
46-
return DECODER_FACTORY.binaryDecoder(buffer, offset, len, prev);
32+
public static BinaryDecoder acquireDecoder() {
33+
return _recycler().claimDecoder();
4734
}
4835

4936
public static BinaryEncoder acquireEncoder() {

0 commit comments

Comments
 (0)