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
All Methods Instance Methods Concrete Methods 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 theirStringvariants of the separated value methods.booleanbooleanValue()booleanbooleanValueLenient()java.nio.CharBuffercharBuffer()Returns aCharBufferholding UTF-8 bytes.java.nio.CharBuffercharBufferOrNull()voidclose()XContentTypecontentType()java.lang.StringcurrentName()XContentParser.TokencurrentToken()doubledoubleValue()doubledoubleValue(boolean coerce)floatfloatValue()floatfloatValue(boolean coerce)DeprecationHandlergetDeprecationHandler()The callback to notify when parsing encounters a deprecated field.XContentLocationgetTokenLocation()Used for error reporting to highlight where syntax errors occur in content being parsed.NamedXContentRegistrygetXContentRegistry()The registry used to resolveXContentParser.namedObject(Class, String, Object).booleanhasTextCharacters()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.intintValue()intintValue(boolean coerce)booleanisBooleanValue()booleanisBooleanValueLenient()returns true if the current value is boolean in nature.booleanisClosed()java.util.List<java.lang.Object>list()java.util.List<java.lang.Object>listOrderedMap()longlongValue()longlongValue(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> TnamedObject(java.lang.Class<T> categoryClass, java.lang.String name, java.lang.Object context)Parse an object by name.XContentParser.TokennextToken()XContentParser.NumberTypenumberType()java.lang.NumbernumberValue()java.lang.ObjectobjectBytes()java.lang.ObjectobjectText()shortshortValue()shortshortValue(boolean coerce)voidskipChildren()java.lang.Stringtext()char[]textCharacters()inttextLength()inttextOffset()java.lang.StringtextOrNull()
-
-
-
Constructor Detail
-
XContentSubParser
public XContentSubParser(XContentParser parser)
-
-
Method Detail
-
contentType
public XContentType contentType()
- Specified by:
contentTypein interfaceXContentParser
-
nextToken
public XContentParser.Token nextToken() throws java.io.IOException
- Specified by:
nextTokenin interfaceXContentParser- Throws:
java.io.IOException
-
skipChildren
public void skipChildren() throws java.io.IOException- Specified by:
skipChildrenin interfaceXContentParser- Throws:
java.io.IOException
-
currentToken
public XContentParser.Token currentToken()
- Specified by:
currentTokenin interfaceXContentParser
-
currentName
public java.lang.String currentName() throws java.io.IOException- Specified by:
currentNamein interfaceXContentParser- Throws:
java.io.IOException
-
map
public java.util.Map<java.lang.String,java.lang.Object> map() throws java.io.IOException- Specified by:
mapin interfaceXContentParser- Throws:
java.io.IOException
-
mapOrdered
public java.util.Map<java.lang.String,java.lang.Object> mapOrdered() throws java.io.IOException- Specified by:
mapOrderedin interfaceXContentParser- Throws:
java.io.IOException
-
mapStrings
public java.util.Map<java.lang.String,java.lang.String> mapStrings() throws java.io.IOException- Specified by:
mapStringsin interfaceXContentParser- Throws:
java.io.IOException
-
mapStringsOrdered
public java.util.Map<java.lang.String,java.lang.String> mapStringsOrdered() throws java.io.IOException- Specified by:
mapStringsOrderedin interfaceXContentParser- Throws:
java.io.IOException
-
list
public java.util.List<java.lang.Object> list() throws java.io.IOException- Specified by:
listin interfaceXContentParser- Throws:
java.io.IOException
-
listOrderedMap
public java.util.List<java.lang.Object> listOrderedMap() throws java.io.IOException- Specified by:
listOrderedMapin interfaceXContentParser- Throws:
java.io.IOException
-
text
public java.lang.String text() throws java.io.IOException- Specified by:
textin interfaceXContentParser- Throws:
java.io.IOException
-
textOrNull
public java.lang.String textOrNull() throws java.io.IOException- Specified by:
textOrNullin interfaceXContentParser- Throws:
java.io.IOException
-
charBufferOrNull
public java.nio.CharBuffer charBufferOrNull() throws java.io.IOException- Specified by:
charBufferOrNullin interfaceXContentParser- Throws:
java.io.IOException
-
charBuffer
public java.nio.CharBuffer charBuffer() throws java.io.IOExceptionDescription copied from interface:XContentParserReturns aCharBufferholding UTF-8 bytes. This method should be used to read text only binary content should be read throughXContentParser.binaryValue()- Specified by:
charBufferin interfaceXContentParser- Throws:
java.io.IOException
-
objectText
public java.lang.Object objectText() throws java.io.IOException- Specified by:
objectTextin interfaceXContentParser- Throws:
java.io.IOException
-
objectBytes
public java.lang.Object objectBytes() throws java.io.IOException- Specified by:
objectBytesin interfaceXContentParser- Throws:
java.io.IOException
-
hasTextCharacters
public boolean hasTextCharacters()
Description copied from interface:XContentParserMethod 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:
hasTextCharactersin interfaceXContentParser
-
textCharacters
public char[] textCharacters() throws java.io.IOException- Specified by:
textCharactersin interfaceXContentParser- Throws:
java.io.IOException
-
textLength
public int textLength() throws java.io.IOException- Specified by:
textLengthin interfaceXContentParser- Throws:
java.io.IOException
-
textOffset
public int textOffset() throws java.io.IOException- Specified by:
textOffsetin interfaceXContentParser- Throws:
java.io.IOException
-
numberValue
public java.lang.Number numberValue() throws java.io.IOException- Specified by:
numberValuein interfaceXContentParser- Throws:
java.io.IOException
-
numberType
public XContentParser.NumberType numberType() throws java.io.IOException
- Specified by:
numberTypein interfaceXContentParser- Throws:
java.io.IOException
-
shortValue
public short shortValue(boolean coerce) throws java.io.IOException- Specified by:
shortValuein interfaceXContentParser- Throws:
java.io.IOException
-
intValue
public int intValue(boolean coerce) throws java.io.IOException- Specified by:
intValuein interfaceXContentParser- Throws:
java.io.IOException
-
longValue
public long longValue(boolean coerce) throws java.io.IOException- Specified by:
longValuein interfaceXContentParser- Throws:
java.io.IOException
-
floatValue
public float floatValue(boolean coerce) throws java.io.IOException- Specified by:
floatValuein interfaceXContentParser- Throws:
java.io.IOException
-
doubleValue
public double doubleValue(boolean coerce) throws java.io.IOException- Specified by:
doubleValuein interfaceXContentParser- Throws:
java.io.IOException
-
shortValue
public short shortValue() throws java.io.IOException- Specified by:
shortValuein interfaceXContentParser- Throws:
java.io.IOException
-
intValue
public int intValue() throws java.io.IOException- Specified by:
intValuein interfaceXContentParser- Throws:
java.io.IOException
-
longValue
public long longValue() throws java.io.IOException- Specified by:
longValuein interfaceXContentParser- Throws:
java.io.IOException
-
floatValue
public float floatValue() throws java.io.IOException- Specified by:
floatValuein interfaceXContentParser- Throws:
java.io.IOException
-
doubleValue
public double doubleValue() throws java.io.IOException- Specified by:
doubleValuein interfaceXContentParser- Throws:
java.io.IOException
-
isBooleanValue
public boolean isBooleanValue() throws java.io.IOException- Specified by:
isBooleanValuein interfaceXContentParser- Returns:
- true iff the current value is either boolean (
trueorfalse) or one of "false", "true". - Throws:
java.io.IOException
-
booleanValue
public boolean booleanValue() throws java.io.IOException- Specified by:
booleanValuein interfaceXContentParser- Throws:
java.io.IOException
-
isBooleanValueLenient
public boolean isBooleanValueLenient() throws java.io.IOExceptionDescription copied from interface:XContentParserreturns 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:
isBooleanValueLenientin interfaceXContentParser- Throws:
java.io.IOException
-
booleanValueLenient
public boolean booleanValueLenient() throws java.io.IOException- Specified by:
booleanValueLenientin interfaceXContentParser- Throws:
java.io.IOException
-
binaryValue
public byte[] binaryValue() throws java.io.IOExceptionDescription copied from interface:XContentParserReads a plain binary value that was written via one of the following methods: as well as via theirStringvariants 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:
binaryValuein interfaceXContentParser- Throws:
java.io.IOException
-
getTokenLocation
public XContentLocation getTokenLocation()
Description copied from interface:XContentParserUsed for error reporting to highlight where syntax errors occur in content being parsed.- Specified by:
getTokenLocationin 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.IOExceptionDescription copied from interface:XContentParserParse an object by name.- Specified by:
namedObjectin interfaceXContentParser- Throws:
java.io.IOException
-
getXContentRegistry
public NamedXContentRegistry getXContentRegistry()
Description copied from interface:XContentParserThe registry used to resolveXContentParser.namedObject(Class, String, Object). Use this when building a sub-parser from this parser.- Specified by:
getXContentRegistryin interfaceXContentParser
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfaceXContentParser
-
getDeprecationHandler
public DeprecationHandler getDeprecationHandler()
Description copied from interface:XContentParserThe callback to notify when parsing encounters a deprecated field.- Specified by:
getDeprecationHandlerin interfaceXContentParser
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-