Skip to content

Commit

Permalink
Fix #1097 (move IOContext down to ParserMinimalBase)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 31, 2023
1 parent 32c7703 commit bdf97cb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
13 changes: 4 additions & 9 deletions src/main/java/tools/jackson/core/base/ParserBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ public abstract class ParserBase extends ParserMinimalBase
/**********************************************************************
*/

/**
* I/O context for this reader. It handles buffer allocation
* for the reader.
*/
protected final IOContext _ioContext;

/**
* Flag that indicates whether parser is closed or not. Gets
* set when parser is either closed by explicit call
Expand Down Expand Up @@ -212,7 +206,6 @@ public abstract class ParserBase extends ParserMinimalBase
protected ParserBase(ObjectReadContext readCtxt,
IOContext ctxt, int streamReadFeatures) {
super(readCtxt, ctxt, streamReadFeatures);
_ioContext = ctxt;
_textBuffer = ctxt.constructReadConstrainedTextBuffer();
}

Expand Down Expand Up @@ -281,8 +274,11 @@ public Object currentValue() {
}
*/

@Override public void close() throws JacksonException {
@Override
public void close() throws JacksonException
{
if (!_closed) {
super.close(); // will close IOContext (bit early but still)
// 19-Jan-2018, tatu: as per [core#440] need to ensure no more data assumed available
_inputPtr = Math.max(_inputPtr, _inputEnd);
_closed = true;
Expand All @@ -294,7 +290,6 @@ public Object currentValue() {
// as per [JACKSON-324], do in finally block
// Also, internal buffer(s) can now be released as well
_releaseBuffers();
_ioContext.close();
}
}
}
Expand Down
36 changes: 22 additions & 14 deletions src/main/java/tools/jackson/core/base/ParserMinimalBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public abstract class ParserMinimalBase extends JsonParser
* {@link tools.jackson.core.StreamReadFeature}s
* are enabled.
*/
protected int _streamReadFeatures;
protected final int _streamReadFeatures;

/**
* Constraints to use for this parser.
Expand All @@ -166,6 +166,14 @@ public abstract class ParserMinimalBase extends JsonParser
*/
protected final ObjectReadContext _objectReadContext;

/**
* I/O context for this reader. It handles buffer allocation
* for the reader, including possible reuse/recycling.
*
* @since 3.0 (at this level)
*/
protected final IOContext _ioContext;

/**
* Last token retrieved via {@link #nextToken}, if any.
* Null before the first call to <code>nextToken()</code>,
Expand All @@ -185,30 +193,24 @@ public abstract class ParserMinimalBase extends JsonParser
/**********************************************************************
*/

// 31-Aug-2023, tatu: To be removed ASAP
/*
protected ParserMinimalBase(ObjectReadContext readCtxt) {
super();
_objectReadContext = readCtxt;
_streamReadFeatures = readCtxt.getStreamReadFeatures(STREAM_READ_FEATURE_DEFAULTS);
_streamReadConstraints = readCtxt.streamReadConstraints();
}

@Deprecated // Not to be used in 3.0?
protected ParserMinimalBase(ObjectReadContext readCtxt,
int streamReadFeatures)
{
super();
_objectReadContext = readCtxt;
_streamReadFeatures = streamReadFeatures;
_streamReadConstraints = readCtxt.streamReadConstraints();
}
*/

protected ParserMinimalBase(ObjectReadContext readCtxt,
IOContext ctxt, int streamReadFeatures)
IOContext ioCtxt, int streamReadFeatures)
{
super();
_objectReadContext = readCtxt;
_ioContext = ioCtxt;
_streamReadFeatures = streamReadFeatures;
_streamReadConstraints = ctxt.streamReadConstraints();
_streamReadConstraints = ioCtxt.streamReadConstraints();
}

/*
Expand Down Expand Up @@ -266,7 +268,13 @@ public StreamReadConstraints streamReadConstraints() {
// public JsonToken getCurrentToken()
// public boolean hasCurrentToken()

// public abstract void close();
@Override
public void close() throws JacksonException
{
// !!! TODO: calls to closeInput(), releaseBuffers()
_ioContext.close();
}

// public abstract boolean isClosed();

/*
Expand Down

0 comments on commit bdf97cb

Please sign in to comment.