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 Sep 2, 2023
2 parents 887e18e + 617145a commit 37bae8b
Showing 1 changed file with 33 additions and 41 deletions.
74 changes: 33 additions & 41 deletions cbor/src/main/java/tools/jackson/dataformat/cbor/CBORParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,38 +469,12 @@ public String currentName()
return _streamReadContext.currentName();
}

@Override
public void close() {
if (!_closed) {
_closed = true;
_symbols.release();
try {
_closeInput();
} finally {
// as per [JACKSON-324], do in finally block
// Also, internal buffer(s) can now be released as well
_releaseBuffers();
}
}
}

/*
/**********************************************************************
/* Overridden methods
/* Abstract methods/overrides, closing parser
/**********************************************************************
*/

@Override
public boolean hasTextCharacters()
{
if (_currToken == JsonToken.VALUE_STRING) {
// yes; is or can be made available efficiently as char[]
return _sharedString != null || _textBuffer.hasTextAsCharacters();
}
// other types, no benefit from accessing as char[]
return false;
}

/**
* Method called to release internal buffers owned by the base
* reader. This may be called along with {@link #_closeInput} (for
Expand All @@ -511,6 +485,7 @@ public boolean hasTextCharacters()
protected void _releaseBuffers()
{
super._releaseBuffers();
_symbols.release();
if (_bufferRecyclable) {
byte[] buf = _inputBuffer;
if (buf != null) {
Expand All @@ -520,6 +495,37 @@ protected void _releaseBuffers()
}
}

@Override
protected void _closeInput() {
if (_inputStream != null) {
if (_ioContext.isResourceManaged() || isEnabled(StreamReadFeature.AUTO_CLOSE_SOURCE)) {
try {
_inputStream.close();
} catch (IOException e) {
throw _wrapIOFailure(e);
}
}
_inputStream = null;
}
}

/*
/**********************************************************************
/* Overridden methods, other
/**********************************************************************
*/

@Override
public boolean hasTextCharacters()
{
if (_currToken == JsonToken.VALUE_STRING) {
// yes; is or can be made available efficiently as char[]
return _sharedString != null || _textBuffer.hasTextAsCharacters();
}
// other types, no benefit from accessing as char[]
return false;
}

/*
/**********************************************************************
/* JsonParser impl
Expand Down Expand Up @@ -3773,20 +3779,6 @@ protected final boolean _tryToLoadToHaveAtLeast(int minAvailable) throws Jackson
return true;
}

@Override
protected void _closeInput() {
if (_inputStream != null) {
if (_ioContext.isResourceManaged() || isEnabled(StreamReadFeature.AUTO_CLOSE_SOURCE)) {
try {
_inputStream.close();
} catch (IOException e) {
throw _wrapIOFailure(e);
}
}
_inputStream = null;
}
}

@Override
protected void _handleEOF() throws StreamReadException {
if (_streamReadContext.inRoot()) {
Expand Down

0 comments on commit 37bae8b

Please sign in to comment.