Top Description Fields Constructors Methods
com.fasterxml.jackson.core.io

public Class IOContext

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Imports
com.fasterxml.jackson.core.ErrorReportConfiguration, .JsonEncoding, .StreamReadConstraints, .StreamWriteConstraints, com.fasterxml.jackson.core.util.BufferRecycler, .ReadConstrainedTextBuffer, .TextBuffer

To limit number of configuration and state objects to pass, all contextual objects that need to be passed by the factory to readers and writers are combined under this object. One instance is created for each reader and writer.

Note

non-final since 2.4, to allow sub-classing.

Field Summary

Modifier and TypeField and Description
protected byte[]
_base64Buffer

Reference to the buffer allocated for temporary use with base64 encoding or decoding.

protected final BufferRecycler
_bufferRecycler

Recycler used for actual allocation/deallocation/reuse

private boolean
protected char[]
_concatCBuffer

Reference to the buffer allocated for buffering it for output, before being encoded: generally this means concatenating output, then encoding when buffer fills up.

protected final ContentReference
_contentReference

Reference to the source object, which can be used for displaying location information

protected JsonEncoding
_encoding

Encoding used by the underlying stream, if known.

protected final ErrorReportConfiguration
protected final boolean
_managedResource

Flag that indicates whether underlying input/output source/target object is fully managed by the owner of this context (parser or generator).

protected char[]
_nameCopyBuffer

Reference temporary buffer Parser instances need if calling app decides it wants to access name via 'getTextCharacters' method.

protected byte[]
_readIOBuffer

Reference to the allocated I/O buffer for low-level input reading, if any allocated.

protected final Object
_sourceRef

Old, deprecated "raw" reference to input source.

protected final StreamReadConstraints
protected final StreamWriteConstraints
protected char[]
_tokenCBuffer

Reference to the buffer allocated for tokenization purposes, in which character input is read, and from which it can be further returned.

protected byte[]
_writeEncodingBuffer

Reference to the allocated I/O buffer used for low-level encoding-related buffering.

Constructor Summary

AccessConstructor and Description
public
IOContext(StreamReadConstraints
constraints for streaming reads
src
,
StreamWriteConstraints
constraints for streaming writes
swc
,
ErrorReportConfiguration
Error report configuration to use
erc
,
BufferRecycler
BufferRecycler to use, if any (null if none)
br
,
ContentReference
Input source reference for location reporting
contentRef
,
boolean
Whether input source is managed (owned) by Jackson library
managedResource
)

Main constructor to use.

public
IOContext(StreamReadConstraints
constraints for streaming reads
src
,
BufferRecycler
BufferRecycler to use, if any (null if none)
br
,
ContentReference
Input source reference for location reporting
contentRef
,
boolean
Whether input source is managed (owned) by Jackson library
managedResource
)

Deprecated Since 2.16.
Deprecated legacy constructor.
public
IOContext(BufferRecycler
BufferRecycler to use, if any (null if none)
br
,
ContentReference
Input source reference for location reporting
contentRef
,
boolean
Whether input source is managed (owned) by Jackson library
managedResource
)

Deprecated Since 2.15.
Deprecated legacy constructor.
public
IOContext(BufferRecycler br, Object rawContent, boolean managedResource)

Deprecated

Method Summary

Modifier and TypeMethod and Description
protected final void
protected final void
_verifyRelease(byte[] toRelease, byte[] src)

protected final void
_verifyRelease(char[] toRelease, char[] src)

public byte[]

Returns:

Allocated or recycled byte buffer
allocBase64Buffer
()

Method for recycling or allocation byte buffer of "base 64 encode/decode" type.

public byte[]

Returns:

Allocated or recycled byte buffer
allocBase64Buffer
(int
Minimum size of the buffer to recycle or allocate
minSize
)

Variant of allocBase64Buffer() that specifies smallest acceptable buffer size.

public char[]
public char[]
allocNameCopyBuffer(int minSize)

public byte[]

Returns:

Allocated or recycled byte buffer
allocReadIOBuffer
()

Method for recycling or allocation byte buffer of "read I/O" type.

public byte[]

Returns:

Allocated or recycled byte buffer
allocReadIOBuffer
(int
Minimum size of the buffer to recycle or allocate
minSize
)

Variant of allocReadIOBuffer() that specifies smallest acceptable buffer size.

public char[]
public char[]
allocTokenBuffer(int minSize)

public byte[]

Returns:

Allocated or recycled byte buffer
allocWriteEncodingBuffer
()

Method for recycling or allocation byte buffer of "write encoding" type.

public byte[]

Returns:

Allocated or recycled byte buffer
allocWriteEncodingBuffer
(int
Minimum size of the buffer to recycle or allocate
minSize
)

Variant of allocWriteEncodingBuffer() that specifies smallest acceptable buffer size.

public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.
public TextBuffer
public TextBuffer
public ContentReference

Returns:

Reference to input source
contentReference
()

Accessor for getting (some) information about input source, mostly usable for error reporting purposes.

public ErrorReportConfiguration

Returns:

Configured ErrorReportConfiguration, containing configured values for handling error reporting.
errorReportConfiguration
()

public JsonEncoding
public Object

Returns:

"Raw" source reference
getSourceReference
()

Deprecated Since 2.13, use contentReference() instead
public boolean
public void
releaseBase64Buffer(byte[] buf)

public void
releaseConcatBuffer(char[] buf)

public void
public void
releaseReadIOBuffer(byte[]
Buffer instance to release (return for recycling)
buf
)

Method to call when all the processing buffers can be safely recycled.

public void
releaseTokenBuffer(char[] buf)

public void
public void
public StreamReadConstraints

Returns:

constraints for streaming reads
streamReadConstraints
()

public StreamWriteConstraints

Returns:

constraints for streaming writes
streamWriteConstraints
()

public IOContext
private IllegalArgumentException
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_base64Bufferback to summary
protected byte[] _base64Buffer

Reference to the buffer allocated for temporary use with base64 encoding or decoding.

_bufferRecyclerback to summary
protected final BufferRecycler _bufferRecycler

Recycler used for actual allocation/deallocation/reuse

_closedback to summary
private boolean _closed
_concatCBufferback to summary
protected char[] _concatCBuffer

Reference to the buffer allocated for buffering it for output, before being encoded: generally this means concatenating output, then encoding when buffer fills up.

_contentReferenceback to summary
protected final ContentReference _contentReference

Reference to the source object, which can be used for displaying location information

_encodingback to summary
protected JsonEncoding _encoding

Encoding used by the underlying stream, if known.

_errorReportConfigurationback to summary
protected final ErrorReportConfiguration _errorReportConfiguration
Since
2.16
_managedResourceback to summary
protected final boolean _managedResource

Flag that indicates whether underlying input/output source/target object is fully managed by the owner of this context (parser or generator). If true, it is, and is to be closed by parser/generator; if false, calling application has to do closing (unless auto-closing feature is enabled for the parser/generator in question; in which case it acts like the owner).

_nameCopyBufferback to summary
protected char[] _nameCopyBuffer

Reference temporary buffer Parser instances need if calling app decides it wants to access name via 'getTextCharacters' method. Regular text buffer can not be used as it may contain textual representation of the value token.

_readIOBufferback to summary
protected byte[] _readIOBuffer

Reference to the allocated I/O buffer for low-level input reading, if any allocated.

_sourceRefback to summary
protected final Object _sourceRef

Deprecated

Since 2.13, use _contentReference instead

Old, deprecated "raw" reference to input source.

Annotations
@Deprecated
_streamReadConstraintsback to summary
protected final StreamReadConstraints _streamReadConstraints
Since
2.15
_streamWriteConstraintsback to summary
protected final StreamWriteConstraints _streamWriteConstraints
Since
2.16
_tokenCBufferback to summary
protected char[] _tokenCBuffer

Reference to the buffer allocated for tokenization purposes, in which character input is read, and from which it can be further returned.

_writeEncodingBufferback to summary
protected byte[] _writeEncodingBuffer

Reference to the allocated I/O buffer used for low-level encoding-related buffering.

Constructor Detail

IOContextback to summary
public IOContext(StreamReadConstraints src, StreamWriteConstraints swc, ErrorReportConfiguration erc, BufferRecycler br, ContentReference contentRef, boolean managedResource)

Main constructor to use.

Parameters
src:StreamReadConstraints

constraints for streaming reads

swc:StreamWriteConstraints

constraints for streaming writes

erc:ErrorReportConfiguration

Error report configuration to use

br:BufferRecycler

BufferRecycler to use, if any (null if none)

contentRef:ContentReference

Input source reference for location reporting

managedResource:boolean

Whether input source is managed (owned) by Jackson library

Since
2.16
IOContextback to summary
public IOContext(StreamReadConstraints src, BufferRecycler br, ContentReference contentRef, boolean managedResource)

Deprecated legacy constructor.

Parameters
src:StreamReadConstraints

constraints for streaming reads

br:BufferRecycler

BufferRecycler to use, if any (null if none)

contentRef:ContentReference

Input source reference for location reporting

managedResource:boolean

Whether input source is managed (owned) by Jackson library

Annotations
@Deprecated
Since
2.15
IOContextback to summary
public IOContext(BufferRecycler br, ContentReference contentRef, boolean managedResource)

Deprecated legacy constructor.

Parameters
br:BufferRecycler

BufferRecycler to use, if any (null if none)

contentRef:ContentReference

Input source reference for location reporting

managedResource:boolean

Whether input source is managed (owned) by Jackson library

Annotations
@Deprecated
Since
2.13
IOContextback to summary
public IOContext(BufferRecycler br, Object rawContent, boolean managedResource)

Deprecated

Annotations
@Deprecated

Method Detail

_verifyAllocback to summary
protected final void _verifyAlloc(Object buffer)
_verifyReleaseback to summary
protected final void _verifyRelease(byte[] toRelease, byte[] src)
_verifyReleaseback to summary
protected final void _verifyRelease(char[] toRelease, char[] src)
allocBase64Bufferback to summary
public byte[] allocBase64Buffer()

Method for recycling or allocation byte buffer of "base 64 encode/decode" type.

Note

the method can only be called once during its life cycle. This is to protect against accidental sharing.

Returns:byte[]

Allocated or recycled byte buffer

allocBase64Bufferback to summary
public byte[] allocBase64Buffer(int minSize)

Variant of allocBase64Buffer() that specifies smallest acceptable buffer size.

Parameters
minSize:int

Minimum size of the buffer to recycle or allocate

Returns:byte[]

Allocated or recycled byte buffer

Since
2.9
allocConcatBufferback to summary
public char[] allocConcatBuffer()
allocNameCopyBufferback to summary
public char[] allocNameCopyBuffer(int minSize)
allocReadIOBufferback to summary
public byte[] allocReadIOBuffer()

Method for recycling or allocation byte buffer of "read I/O" type.

Note

the method can only be called once during its life cycle. This is to protect against accidental sharing.

Returns:byte[]

Allocated or recycled byte buffer

allocReadIOBufferback to summary
public byte[] allocReadIOBuffer(int minSize)

Variant of allocReadIOBuffer() that specifies smallest acceptable buffer size.

Parameters
minSize:int

Minimum size of the buffer to recycle or allocate

Returns:byte[]

Allocated or recycled byte buffer

Since
2.4
allocTokenBufferback to summary
public char[] allocTokenBuffer()
allocTokenBufferback to summary
public char[] allocTokenBuffer(int minSize)
allocWriteEncodingBufferback to summary
public byte[] allocWriteEncodingBuffer()

Method for recycling or allocation byte buffer of "write encoding" type.

Note

the method can only be called once during its life cycle. This is to protect against accidental sharing.

Returns:byte[]

Allocated or recycled byte buffer

allocWriteEncodingBufferback to summary
public byte[] allocWriteEncodingBuffer(int minSize)

Variant of allocWriteEncodingBuffer() that specifies smallest acceptable buffer size.

Parameters
minSize:int

Minimum size of the buffer to recycle or allocate

Returns:byte[]

Allocated or recycled byte buffer

Since
2.4
closeback to summary
public void close()

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
constructReadConstrainedTextBufferback to summary
public TextBuffer constructReadConstrainedTextBuffer()
constructTextBufferback to summary
public TextBuffer constructTextBuffer()
contentReferenceback to summary
public ContentReference contentReference()

Accessor for getting (some) information about input source, mostly usable for error reporting purposes.

Returns:ContentReference

Reference to input source

Since
2.13
errorReportConfigurationback to summary
public ErrorReportConfiguration errorReportConfiguration()
Returns:ErrorReportConfiguration

Configured ErrorReportConfiguration, containing configured values for handling error reporting.

Since
2.16
getEncodingback to summary
public JsonEncoding getEncoding()
getSourceReferenceback to summary
public Object getSourceReference()

Deprecated

Since 2.13, use contentReference() instead

Returns:Object

"Raw" source reference

Annotations
@Deprecated
isResourceManagedback to summary
public boolean isResourceManaged()
releaseBase64Bufferback to summary
public void releaseBase64Buffer(byte[] buf)
releaseConcatBufferback to summary
public void releaseConcatBuffer(char[] buf)
releaseNameCopyBufferback to summary
public void releaseNameCopyBuffer(char[] buf)
releaseReadIOBufferback to summary
public void releaseReadIOBuffer(byte[] buf)

Method to call when all the processing buffers can be safely recycled.

Parameters
buf:byte[]

Buffer instance to release (return for recycling)

releaseTokenBufferback to summary
public void releaseTokenBuffer(char[] buf)
releaseWriteEncodingBufferback to summary
public void releaseWriteEncodingBuffer(byte[] buf)
setEncodingback to summary
public void setEncoding(JsonEncoding enc)
streamReadConstraintsback to summary
public StreamReadConstraints streamReadConstraints()
Returns:StreamReadConstraints

constraints for streaming reads

Since
2.15
streamWriteConstraintsback to summary
public StreamWriteConstraints streamWriteConstraints()
Returns:StreamWriteConstraints

constraints for streaming writes

Since
2.16
withEncodingback to summary
public IOContext withEncoding(JsonEncoding enc)
wrongBufback to summary
private IllegalArgumentException wrongBuf()