Top Description Fields Constructors Methods
tools.jackson.core.io

public Class IOContext

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Imports
java.util.Objects, tools.jackson.core.ErrorReportConfiguration, .JsonEncoding, .StreamReadConstraints, .StreamWriteConstraints, tools.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.

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 boolean
_releaseRecycler

Flag that indicates whether this context instance should release configured _bufferRecycler or not: if it does, it needs to call (via BufferRecycler#releaseToPool() when closed; if not, should do nothing (recycler life-cycle is externally managed)

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
Configuration for error reporting
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
,
JsonEncoding
Encoding in use
enc
)

Main constructor to use.

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 BufferRecycler
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 boolean
public IOContext
markBufferRecyclerReleased()

Method to call to prevent _bufferRecycler release upon close(): called when _bufferRecycler life-cycle is externally managed.

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 IOContext
public StreamReadConstraints

Returns:

constraints for streaming reads
streamReadConstraints
()

public StreamWriteConstraints

Returns:

constraints for streaming writes
streamWriteConstraints
()

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
_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 cannot 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.

_releaseRecyclerback to summary
protected boolean _releaseRecycler

Flag that indicates whether this context instance should release configured _bufferRecycler or not: if it does, it needs to call (via BufferRecycler#releaseToPool() when closed; if not, should do nothing (recycler life-cycle is externally managed)

_streamReadConstraintsback to summary
protected final StreamReadConstraints _streamReadConstraints
_streamWriteConstraintsback to summary
protected final StreamWriteConstraints _streamWriteConstraints
_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, JsonEncoding enc)

Main constructor to use.

Parameters
src:StreamReadConstraints

Constraints for streaming reads

swc:StreamWriteConstraints

Constraints for streaming writes

erc:ErrorReportConfiguration

Configuration for error reporting

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

enc:JsonEncoding

Encoding in use

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

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

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

bufferRecyclerback to summary
public BufferRecycler bufferRecycler()
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

errorReportConfigurationback to summary
public ErrorReportConfiguration errorReportConfiguration()
Returns:ErrorReportConfiguration

Configured ErrorReportConfiguration, containing configured values for handling error reporting.

getEncodingback to summary
public JsonEncoding getEncoding()
isResourceManagedback to summary
public boolean isResourceManaged()
markBufferRecyclerReleasedback to summary
public IOContext markBufferRecyclerReleased()

Method to call to prevent _bufferRecycler release upon close(): called when _bufferRecycler life-cycle is externally managed.

Since
2.17
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 IOContext setEncoding(JsonEncoding enc)
streamReadConstraintsback to summary
public StreamReadConstraints streamReadConstraints()
Returns:StreamReadConstraints

constraints for streaming reads

streamWriteConstraintsback to summary
public StreamWriteConstraints streamWriteConstraints()
Returns:StreamWriteConstraints

constraints for streaming writes

wrongBufback to summary
private IllegalArgumentException wrongBuf()