Package com.fasterxml.jackson.core.io
Class ContentReference
- java.lang.Object
-
- com.fasterxml.jackson.core.io.ContentReference
-
- All Implemented Interfaces:
java.io.Serializable
public class ContentReference extends java.lang.Object implements java.io.SerializableAbstraction that encloses information about content being processed -- input source or output target, streaming or not -- for the purpose of including pertinent information in location (seeJsonLocation) objections, most commonly to be printed out as part ofExceptionmessages.- Since:
- 2.13
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_isContentTextualMarker 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 int_lengthFor static content, indicates length of content in the static array.protected int_offsetFor static content, indicates offset from the beginning of static array.protected java.lang.Object_rawContentReference to the actual underlying content.static intDEFAULT_MAX_CONTENT_SNIPPETInclude at most first 500 characters/bytes from contents; should be enough to give context, but not cause unfortunate side effects in things like logs.protected static ContentReferenceUNKNOWN_CONTENTConstant that may be used when source/target content is not known (or not exposed).
-
Constructor Summary
Constructors Modifier Constructor Description protectedContentReference(boolean isContentTextual, java.lang.Object rawContent)protectedContentReference(boolean isContentTextual, java.lang.Object rawContent, int offset, int length)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int_append(java.lang.StringBuilder sb, java.lang.String content)protected boolean_appendEscaped(java.lang.StringBuilder sb, int ctrlChar)protected java.lang.String_truncate(byte[] b, int[] offsets, int maxSnippetLen)protected java.lang.String_truncate(char[] cs, int[] offsets, int maxSnippetLen)protected java.lang.String_truncate(java.lang.CharSequence cs, int[] offsets, int maxSnippetLen)protected void_truncateOffsets(int[] offsets, int actualLength)java.lang.StringBuilderappendSourceDescription(java.lang.StringBuilder sb)Method for appending a "source description" when content represented by this reference is read.java.lang.StringbuildSourceDescription()Method for constructing a "source description" when content represented by this reference is read.static ContentReferenceconstruct(boolean isContentTextual, java.lang.Object rawContent)static ContentReferenceconstruct(boolean isContentTextual, java.lang.Object rawContent, int offset, int length)intcontentLength()intcontentOffset()booleanequals(java.lang.Object other)java.lang.ObjectgetRawContent()inthashCode()booleanhasTextualContent()protected intmaxContentSnippetLength()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 ContentReferencerawReference(boolean isContentTextual, java.lang.Object rawContent)Factory method for legacy code to use for constructing instances to content about which only minimal amount of information is available.static ContentReferencerawReference(java.lang.Object rawContent)protected java.lang.ObjectreadResolve()static ContentReferenceunknown()Accessor for getting a placeholder for cases where actual content is not known (or is not something that system wants to expose).
-
-
-
Field Detail
-
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.
-
DEFAULT_MAX_CONTENT_SNIPPET
public static final int DEFAULT_MAX_CONTENT_SNIPPET
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 java.lang.Object _rawContent
Reference to the actual underlying content.
-
_offset
protected final int _offset
For static content, indicates offset from the beginning of static array.-1if not in use.
-
_length
protected final int _length
For static content, indicates length of content in the static array.-1if 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.
-
-
Method Detail
-
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
nullreference
-
construct
public static ContentReference construct(boolean isContentTextual, java.lang.Object rawContent)
-
construct
public static ContentReference construct(boolean isContentTextual, java.lang.Object rawContent, int offset, int length)
-
rawReference
public static ContentReference rawReference(boolean isContentTextual, java.lang.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(java.lang.Object rawContent)
-
readResolve
protected java.lang.Object readResolve()
-
hasTextualContent
public boolean hasTextualContent()
-
getRawContent
public java.lang.Object getRawContent()
-
contentOffset
public int contentOffset()
-
contentLength
public int contentLength()
-
maxContentSnippetLength
protected int maxContentSnippetLength()
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
-
buildSourceDescription
public java.lang.String buildSourceDescription()
Method for constructing a "source description" when content represented by this reference is read.- Returns:
- Description constructed
-
appendSourceDescription
public java.lang.StringBuilder appendSourceDescription(java.lang.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 java.lang.String _truncate(java.lang.CharSequence cs, int[] offsets, int maxSnippetLen)
-
_truncate
protected java.lang.String _truncate(char[] cs, int[] offsets, int maxSnippetLen)
-
_truncate
protected java.lang.String _truncate(byte[] b, int[] offsets, int maxSnippetLen)
-
_truncateOffsets
protected void _truncateOffsets(int[] offsets, int actualLength)
-
_append
protected int _append(java.lang.StringBuilder sb, java.lang.String content)
-
_appendEscaped
protected boolean _appendEscaped(java.lang.StringBuilder sb, int ctrlChar)
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-