Class XContentSubParser
- java.lang.Object
-
- org.elasticsearch.common.xcontent.XContentSubParser
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,XContentParser
public class XContentSubParser extends java.lang.Object implements XContentParser
Wrapper for a XContentParser that makes a single object to look like a complete document. The wrapper prevents the parsing logic to consume tokens outside of the wrapped object as well as skipping to the end of the object in case of a parsing error. The wrapper is intended to be used for parsing objects that should be ignored if they are malformed.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.XContentParser
XContentParser.NumberType, XContentParser.Token
-
-
Constructor Summary
Constructors Constructor Description XContentSubParser(XContentParser parser)
-
Method Summary
Modifier and Type Method Description byte[]
binaryValue()
Reads a plain binary value that was written via one of the following methods:XContentBuilder.field(String, byte[], int, int)
}XContentBuilder.field(String, byte[])
} as well as via theirString
variants of the separated value methods.boolean
booleanValue()
boolean
booleanValueLenient()
java.nio.CharBuffer
charBuffer()
Returns aCharBuffer
holding UTF-8 bytes.java.nio.CharBuffer
charBufferOrNull()
void
close()
XContentType
contentType()
java.lang.String
currentName()
XContentParser.Token
currentToken()
double
doubleValue()
double
doubleValue(boolean coerce)
float
floatValue()
float
floatValue(boolean coerce)
DeprecationHandler
getDeprecationHandler()
The callback to notify when parsing encounters a deprecated field.XContentLocation
getTokenLocation()
Used for error reporting to highlight where syntax errors occur in content being parsed.NamedXContentRegistry
getXContentRegistry()
The registry used to resolveXContentParser.namedObject(Class, String, Object)
.boolean
hasTextCharacters()
Method that can be used to determine whether calling of textCharacters() would be the most efficient way to access textual content for the event parser currently points to.int
intValue()
int
intValue(boolean coerce)
boolean
isBooleanValue()
boolean
isBooleanValueLenient()
returns true if the current value is boolean in nature.boolean
isClosed()
java.util.List<java.lang.Object>
list()
java.util.List<java.lang.Object>
listOrderedMap()
long
longValue()
long
longValue(boolean coerce)
java.util.Map<java.lang.String,java.lang.Object>
map()
java.util.Map<java.lang.String,java.lang.Object>
mapOrdered()
java.util.Map<java.lang.String,java.lang.String>
mapStrings()
java.util.Map<java.lang.String,java.lang.String>
mapStringsOrdered()
<T> T
namedObject(java.lang.Class<T> categoryClass, java.lang.String name, java.lang.Object context)
Parse an object by name.XContentParser.Token
nextToken()
XContentParser.NumberType
numberType()
java.lang.Number
numberValue()
java.lang.Object
objectBytes()
java.lang.Object
objectText()
short
shortValue()
short
shortValue(boolean coerce)
void
skipChildren()
java.lang.String
text()
char[]
textCharacters()
int
textLength()
int
textOffset()
java.lang.String
textOrNull()
-
-
-
Constructor Detail
-
XContentSubParser
public XContentSubParser(XContentParser parser)
-
-
Method Detail
-
contentType
public XContentType contentType()
- Specified by:
contentType
in interfaceXContentParser
-
nextToken
public XContentParser.Token nextToken() throws java.io.IOException
- Specified by:
nextToken
in interfaceXContentParser
- Throws:
java.io.IOException
-
skipChildren
public void skipChildren() throws java.io.IOException
- Specified by:
skipChildren
in interfaceXContentParser
- Throws:
java.io.IOException
-
currentToken
public XContentParser.Token currentToken()
- Specified by:
currentToken
in interfaceXContentParser
-
currentName
public java.lang.String currentName() throws java.io.IOException
- Specified by:
currentName
in interfaceXContentParser
- Throws:
java.io.IOException
-
map
public java.util.Map<java.lang.String,java.lang.Object> map() throws java.io.IOException
- Specified by:
map
in interfaceXContentParser
- Throws:
java.io.IOException
-
mapOrdered
public java.util.Map<java.lang.String,java.lang.Object> mapOrdered() throws java.io.IOException
- Specified by:
mapOrdered
in interfaceXContentParser
- Throws:
java.io.IOException
-
mapStrings
public java.util.Map<java.lang.String,java.lang.String> mapStrings() throws java.io.IOException
- Specified by:
mapStrings
in interfaceXContentParser
- Throws:
java.io.IOException
-
mapStringsOrdered
public java.util.Map<java.lang.String,java.lang.String> mapStringsOrdered() throws java.io.IOException
- Specified by:
mapStringsOrdered
in interfaceXContentParser
- Throws:
java.io.IOException
-
list
public java.util.List<java.lang.Object> list() throws java.io.IOException
- Specified by:
list
in interfaceXContentParser
- Throws:
java.io.IOException
-
listOrderedMap
public java.util.List<java.lang.Object> listOrderedMap() throws java.io.IOException
- Specified by:
listOrderedMap
in interfaceXContentParser
- Throws:
java.io.IOException
-
text
public java.lang.String text() throws java.io.IOException
- Specified by:
text
in interfaceXContentParser
- Throws:
java.io.IOException
-
textOrNull
public java.lang.String textOrNull() throws java.io.IOException
- Specified by:
textOrNull
in interfaceXContentParser
- Throws:
java.io.IOException
-
charBufferOrNull
public java.nio.CharBuffer charBufferOrNull() throws java.io.IOException
- Specified by:
charBufferOrNull
in interfaceXContentParser
- Throws:
java.io.IOException
-
charBuffer
public java.nio.CharBuffer charBuffer() throws java.io.IOException
Description copied from interface:XContentParser
Returns aCharBuffer
holding UTF-8 bytes. This method should be used to read text only binary content should be read throughXContentParser.binaryValue()
- Specified by:
charBuffer
in interfaceXContentParser
- Throws:
java.io.IOException
-
objectText
public java.lang.Object objectText() throws java.io.IOException
- Specified by:
objectText
in interfaceXContentParser
- Throws:
java.io.IOException
-
objectBytes
public java.lang.Object objectBytes() throws java.io.IOException
- Specified by:
objectBytes
in interfaceXContentParser
- Throws:
java.io.IOException
-
hasTextCharacters
public boolean hasTextCharacters()
Description copied from interface:XContentParser
Method that can be used to determine whether calling of textCharacters() would be the most efficient way to access textual content for the event parser currently points to. Default implementation simply returns false since only actual implementation class has knowledge of its internal buffering state. This method shouldn't be used to check if the token contains text or not.- Specified by:
hasTextCharacters
in interfaceXContentParser
-
textCharacters
public char[] textCharacters() throws java.io.IOException
- Specified by:
textCharacters
in interfaceXContentParser
- Throws:
java.io.IOException
-
textLength
public int textLength() throws java.io.IOException
- Specified by:
textLength
in interfaceXContentParser
- Throws:
java.io.IOException
-
textOffset
public int textOffset() throws java.io.IOException
- Specified by:
textOffset
in interfaceXContentParser
- Throws:
java.io.IOException
-
numberValue
public java.lang.Number numberValue() throws java.io.IOException
- Specified by:
numberValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
numberType
public XContentParser.NumberType numberType() throws java.io.IOException
- Specified by:
numberType
in interfaceXContentParser
- Throws:
java.io.IOException
-
shortValue
public short shortValue(boolean coerce) throws java.io.IOException
- Specified by:
shortValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
intValue
public int intValue(boolean coerce) throws java.io.IOException
- Specified by:
intValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
longValue
public long longValue(boolean coerce) throws java.io.IOException
- Specified by:
longValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
floatValue
public float floatValue(boolean coerce) throws java.io.IOException
- Specified by:
floatValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
doubleValue
public double doubleValue(boolean coerce) throws java.io.IOException
- Specified by:
doubleValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
shortValue
public short shortValue() throws java.io.IOException
- Specified by:
shortValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
intValue
public int intValue() throws java.io.IOException
- Specified by:
intValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
longValue
public long longValue() throws java.io.IOException
- Specified by:
longValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
floatValue
public float floatValue() throws java.io.IOException
- Specified by:
floatValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
doubleValue
public double doubleValue() throws java.io.IOException
- Specified by:
doubleValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
isBooleanValue
public boolean isBooleanValue() throws java.io.IOException
- Specified by:
isBooleanValue
in interfaceXContentParser
- Returns:
- true iff the current value is either boolean (
true
orfalse
) or one of "false", "true". - Throws:
java.io.IOException
-
booleanValue
public boolean booleanValue() throws java.io.IOException
- Specified by:
booleanValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
isBooleanValueLenient
public boolean isBooleanValueLenient() throws java.io.IOException
Description copied from interface:XContentParser
returns true if the current value is boolean in nature. values that are considered booleans: - boolean value (true/false) - numeric integers (=0 is considered as false, !=0 is true) - one of the following strings: "true","false","on","off","yes","no","1","0"- Specified by:
isBooleanValueLenient
in interfaceXContentParser
- Throws:
java.io.IOException
-
booleanValueLenient
public boolean booleanValueLenient() throws java.io.IOException
- Specified by:
booleanValueLenient
in interfaceXContentParser
- Throws:
java.io.IOException
-
binaryValue
public byte[] binaryValue() throws java.io.IOException
Description copied from interface:XContentParser
Reads a plain binary value that was written via one of the following methods: as well as via theirString
variants of the separated value methods. Note: Do not use this method to read values written with: these methods write UTF-8 encoded strings and must be read through:- Specified by:
binaryValue
in interfaceXContentParser
- Throws:
java.io.IOException
-
getTokenLocation
public XContentLocation getTokenLocation()
Description copied from interface:XContentParser
Used for error reporting to highlight where syntax errors occur in content being parsed.- Specified by:
getTokenLocation
in interfaceXContentParser
- Returns:
- last token's location or null if cannot be determined
-
namedObject
public <T> T namedObject(java.lang.Class<T> categoryClass, java.lang.String name, java.lang.Object context) throws java.io.IOException
Description copied from interface:XContentParser
Parse an object by name.- Specified by:
namedObject
in interfaceXContentParser
- Throws:
java.io.IOException
-
getXContentRegistry
public NamedXContentRegistry getXContentRegistry()
Description copied from interface:XContentParser
The registry used to resolveXContentParser.namedObject(Class, String, Object)
. Use this when building a sub-parser from this parser.- Specified by:
getXContentRegistry
in interfaceXContentParser
-
isClosed
public boolean isClosed()
- Specified by:
isClosed
in interfaceXContentParser
-
getDeprecationHandler
public DeprecationHandler getDeprecationHandler()
Description copied from interface:XContentParser
The callback to notify when parsing encounters a deprecated field.- Specified by:
getDeprecationHandler
in interfaceXContentParser
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-