Package com.fasterxml.jackson.core.io

# Class ContentReference

java.lang.Object
com.fasterxml.jackson.core.io.ContentReference

All Implemented Interfaces:
  `Serializable`

public class ContentReference extends Object implements Serializable
Abstraction that encloses information about content being processed -- input source or output target, streaming or not -- for the purpose of including pertinent information in location (see `JsonLocation`) objections, most commonly to be printed out as part of `Exception` messages.

Since:
  2.13
See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final boolean`
`_isContentTextual`
Marker flag to indicate whether included content is textual or not: this is taken to mean, by default, that a snippet of content may be displayed for exception messages.
`protected final int`
`_length`
For static content, indicates length of content in the static array.
`protected final int`
`_maxRawContentLength`
max raw content to return as configured
`protected final int`
`_offset`
For static content, indicates offset from the beginning of static array.
`protected final Object`
`_rawContent`
Reference to the actual underlying content.
`static final int`
`DEFAULT_MAX_CONTENT_SNIPPET`
Deprecated.
Since 2.16.
`protected static final ContentReference`
`REDACTED_CONTENT`
As content will be redacted by default in Jackson 2.16 and later, we'll use a new marker reference for slightly different description from "unknown", to indicate explicit removal of source/content reference (as opposed to it missing from not being available or so)
`protected static final ContentReference`
`UNKNOWN_CONTENT`
Constant that may be used when source/target content is not known (or not exposed).

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`ContentReference(boolean isContentTextual, Object rawContent)`
Deprecated.
Since 2.16.
`protected`
`ContentReference(boolean isContentTextual, Object rawContent, int offset, int length)`
Deprecated.
Since 2.16.
`protected`
`ContentReference(boolean isContentTextual, Object rawContent, int offset, int length, ErrorReportConfiguration errorReportConfiguration)`
`protected`
`ContentReference(boolean isContentTextual, Object rawContent, ErrorReportConfiguration errorReportConfiguration)`

## Method Summary

Modifier and Type
Method
Description
`protected int`
`_append(StringBuilder sb, String content)`
`protected boolean`
`_appendEscaped(StringBuilder sb, int ctrlChar)`
`protected String`
`_truncate(byte[] b, int[] offsets, int maxSnippetLen)`
`protected String`
`_truncate(char[] cs, int[] offsets, int maxSnippetLen)`
`protected String`
`_truncate(CharSequence cs, int[] offsets, int maxSnippetLen)`
`protected void`
`_truncateOffsets(int[] offsets, int actualLength)`
`StringBuilder`
`appendSourceDescription(StringBuilder sb)`
Method for appending a "source description" when content represented by this reference is read.
`String`
`buildSourceDescription()`
Method for constructing a "source description" when content represented by this reference is read.
`static ContentReference`
`construct(boolean isContentTextual, Object rawContent)`
Deprecated.
Since 2.16.
`static ContentReference`
`construct(boolean isContentTextual, Object rawContent, int offset, int length)`
Deprecated.
Since 2.16.
`static ContentReference`
`construct(boolean isContentTextual, Object rawContent, int offset, int length, ErrorReportConfiguration errorReportConfiguration)`
`static ContentReference`
`construct(boolean isContentTextual, Object rawContent, ErrorReportConfiguration errorReportConfiguration)`
`int`
`contentLength()`
`int`
`contentOffset()`
`boolean`
`equals(Object other)`
`Object`
`getRawContent()`
`int`
`hashCode()`
`boolean`
`hasTextualContent()`
`protected int`
`maxRawContentLength()`
Internal accessor, overridable, used for checking length (in units in which content is counted, either bytes or chars) to use for truncation (so as not to include full content for humongous sources or targets)
`static ContentReference`
`rawReference(boolean isContentTextual, Object rawContent)`
Factory method for legacy code to use for constructing instances to content about which only minimal amount of information is available.
`static ContentReference`
`rawReference(Object rawContent)`
`protected Object`
`readResolve()`
`static ContentReference`
`redacted()`
Accessor for getting a placeholder when actual content is not to be exposed: different from `unknown()` where content is not available to be referenced.
`static ContentReference`
`unknown()`
Accessor for getting a placeholder for cases where actual content is not known (or is not something that system wants to expose).

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### UNKNOWN_CONTENT

protected static final ContentReference UNKNOWN_CONTENT
Constant that may be used when source/target content is not known (or not exposed).

NOTE: As of 2.13 assume to contain Binary content, meaning that no content snippets will be included.

### REDACTED_CONTENT

protected static final ContentReference REDACTED_CONTENT
As content will be redacted by default in Jackson 2.16 and later, we'll use a new marker reference for slightly different description from "unknown", to indicate explicit removal of source/content reference (as opposed to it missing from not being available or so)

Since:
  2.16

### DEFAULT_MAX_CONTENT_SNIPPET

@Deprecated public static final int DEFAULT_MAX_CONTENT_SNIPPET
Deprecated.
Since 2.16. `ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH` will be used instead.
Include at most first 500 characters/bytes from contents; should be enough to give context, but not cause unfortunate side effects in things like logs.

Since:
  2.9
See Also:
  - Constant Field Values

### _rawContent

protected final transient Object _rawContent
Reference to the actual underlying content.

### _offset

protected final int _offset
For static content, indicates offset from the beginning of static array. `-1` if not in use.

### _length

protected final int _length
For static content, indicates length of content in the static array. `-1` if not in use.

### _isContentTextual

protected final boolean _isContentTextual
Marker flag to indicate whether included content is textual or not: this is taken to mean, by default, that a snippet of content may be displayed for exception messages.

### _maxRawContentLength

protected final int _maxRawContentLength
max raw content to return as configured

Since:
  2.16

## Constructor Details

### ContentReference

@Deprecated protected ContentReference(boolean isContentTextual, Object rawContent)
Deprecated.
Since 2.16. Use `ContentReference(boolean, Object, ErrorReportConfiguration)` instead.

### ContentReference

@Deprecated protected ContentReference(boolean isContentTextual, Object rawContent, int offset, int length)
Deprecated.
Since 2.16. Use `ContentReference(boolean, Object, int, int, ErrorReportConfiguration)` instead.

### ContentReference

protected ContentReference(boolean isContentTextual, Object rawContent, ErrorReportConfiguration errorReportConfiguration)

Since:
  2.16

### ContentReference

protected ContentReference(boolean isContentTextual, Object rawContent, int offset, int length, ErrorReportConfiguration errorReportConfiguration)

Since:
  2.16

## Method Details

### unknown

public static ContentReference unknown()
Accessor for getting a placeholder for cases where actual content is not known (or is not something that system wants to expose).

Returns:
  Placeholder "unknown" (or "empty") instance to use instead of `null` reference

### redacted

public static ContentReference redacted()
Accessor for getting a placeholder when actual content is not to be exposed: different from `unknown()` where content is not available to be referenced.

Returns:
  Placeholder instance to use in cases where reference is explicitly blocked, usually for security reasons.
Since:
  2.16

### construct

@Deprecated public static ContentReference construct(boolean isContentTextual, Object rawContent)
Deprecated.
Since 2.16. Use `construct(boolean, Object, ErrorReportConfiguration)` instead.

### construct

@Deprecated public static ContentReference construct(boolean isContentTextual, Object rawContent, int offset, int length)
Deprecated.
Since 2.16. Use `construct(boolean, Object, int, int, ErrorReportConfiguration)` instead.

### construct

public static ContentReference construct(boolean isContentTextual, Object rawContent, int offset, int length, ErrorReportConfiguration errorReportConfiguration)

Since:
  2.16

### construct

public static ContentReference construct(boolean isContentTextual, Object rawContent, ErrorReportConfiguration errorReportConfiguration)

Since:
  2.16

### rawReference

public static ContentReference rawReference(boolean isContentTextual, Object rawContent)
Factory method for legacy code to use for constructing instances to content about which only minimal amount of information is available. Assumed not to contain textual content (no snippet displayed).

Parameters:
  `isContentTextual` - Is raw content assumed to have textual content (`true`) or binary (`false`)
  `rawContent` - Underlying raw content access
Returns:
  Instance with minimal information about content (basically just raw content reference without offsets

### rawReference

public static ContentReference rawReference(Object rawContent)

### readResolve

protected Object readResolve()

### hasTextualContent

public boolean hasTextualContent()

### getRawContent

public Object getRawContent()

### contentOffset

public int contentOffset()

### contentLength

public int contentLength()

### maxRawContentLength

protected int maxRawContentLength()
Internal accessor, overridable, used for checking length (in units in which content is counted, either bytes or chars) to use for truncation (so as not to include full content for humongous sources or targets)

Returns:
  Maximum content snippet to include before truncating
See Also:
  - `ErrorReportConfiguration.getMaxRawContentLength()`

### buildSourceDescription

public String buildSourceDescription()
Method for constructing a "source description" when content represented by this reference is read.

Returns:
  Description constructed

### appendSourceDescription

public StringBuilder appendSourceDescription(StringBuilder sb)
Method for appending a "source description" when content represented by this reference is read.

Parameters:
  `sb` - StringBuilder to append description to
Returns:
  StringBuilder passed as argument (for call chaining)

### _truncate

protected String _truncate(CharSequence cs, int[] offsets, int maxSnippetLen)

### _truncate

protected String _truncate(char[] cs, int[] offsets, int maxSnippetLen)

### _truncate

protected String _truncate(byte[] b, int[] offsets, int maxSnippetLen)

### _truncateOffsets

protected void _truncateOffsets(int[] offsets, int actualLength)

### _append

protected int _append(StringBuilder sb, String content)

### _appendEscaped

protected boolean _appendEscaped(StringBuilder sb, int ctrlChar)

### equals

public boolean equals(Object other)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`