Package org.elasticsearch.xcontent
Class XContentSubParser
java.lang.Object
org.elasticsearch.xcontent.XContentSubParser
- All Implemented Interfaces:
Closeable
,AutoCloseable
,XContentParser
Wrapper for a XContentParser that makes a single object/array 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.xcontent.XContentParser
XContentParser.NumberType, XContentParser.Token
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
allowDuplicateKeys
(boolean allowDuplicateKeys) byte[]
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
Returns aCharBuffer
holding UTF-8 bytes.void
close()
double
double
doubleValue
(boolean coerce) float
float
floatValue
(boolean coerce) The callback to notify when parsing encounters a deprecated field.Used for error reporting to highlight where syntax errors occur in content being parsed.The registry used to resolveXContentParser.namedObject(Class, String, Object)
.boolean
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
boolean
isClosed()
list()
long
long
longValue
(boolean coerce) map()
map
(Supplier<Map<String, T>> mapFactory, CheckedFunction<XContentParser, T, IOException> mapValueParser) Returns an instance ofMap
holding parsed map.<T> T
namedObject
(Class<T> categoryClass, String name, Object context) Parse an object by name.short
short
shortValue
(boolean coerce) void
text()
char[]
int
int
-
Constructor Details
-
XContentSubParser
-
-
Method Details
-
contentType
- Specified by:
contentType
in interfaceXContentParser
-
allowDuplicateKeys
public void allowDuplicateKeys(boolean allowDuplicateKeys) - Specified by:
allowDuplicateKeys
in interfaceXContentParser
-
nextToken
- Specified by:
nextToken
in interfaceXContentParser
- Throws:
IOException
-
skipChildren
- Specified by:
skipChildren
in interfaceXContentParser
- Throws:
IOException
-
currentToken
- Specified by:
currentToken
in interfaceXContentParser
-
currentName
- Specified by:
currentName
in interfaceXContentParser
- Throws:
IOException
-
map
- Specified by:
map
in interfaceXContentParser
- Throws:
IOException
-
mapOrdered
- Specified by:
mapOrdered
in interfaceXContentParser
- Throws:
IOException
-
mapStrings
- Specified by:
mapStrings
in interfaceXContentParser
- Throws:
IOException
-
map
public <T> Map<String,T> map(Supplier<Map<String, T>> mapFactory, CheckedFunction<XContentParser, throws IOExceptionT, IOException> mapValueParser) Description copied from interface:XContentParser
Returns an instance ofMap
holding parsed map. Serves as a replacement for the "map", "mapOrdered" and "mapStrings" methods above.- Specified by:
map
in interfaceXContentParser
- Type Parameters:
T
- map value type- Parameters:
mapFactory
- factory for creating newMap
objectsmapValueParser
- parser for parsing a single map value- Returns:
Map
object- Throws:
IOException
-
list
- Specified by:
list
in interfaceXContentParser
- Throws:
IOException
-
listOrderedMap
- Specified by:
listOrderedMap
in interfaceXContentParser
- Throws:
IOException
-
text
- Specified by:
text
in interfaceXContentParser
- Throws:
IOException
-
textOrNull
- Specified by:
textOrNull
in interfaceXContentParser
- Throws:
IOException
-
charBufferOrNull
- Specified by:
charBufferOrNull
in interfaceXContentParser
- Throws:
IOException
-
charBuffer
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:
IOException
-
objectText
- Specified by:
objectText
in interfaceXContentParser
- Throws:
IOException
-
objectBytes
- Specified by:
objectBytes
in interfaceXContentParser
- Throws:
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
- Specified by:
textCharacters
in interfaceXContentParser
- Throws:
IOException
-
textLength
- Specified by:
textLength
in interfaceXContentParser
- Throws:
IOException
-
textOffset
- Specified by:
textOffset
in interfaceXContentParser
- Throws:
IOException
-
numberValue
- Specified by:
numberValue
in interfaceXContentParser
- Throws:
IOException
-
numberType
- Specified by:
numberType
in interfaceXContentParser
- Throws:
IOException
-
shortValue
- Specified by:
shortValue
in interfaceXContentParser
- Throws:
IOException
-
intValue
- Specified by:
intValue
in interfaceXContentParser
- Throws:
IOException
-
longValue
- Specified by:
longValue
in interfaceXContentParser
- Throws:
IOException
-
floatValue
- Specified by:
floatValue
in interfaceXContentParser
- Throws:
IOException
-
doubleValue
- Specified by:
doubleValue
in interfaceXContentParser
- Throws:
IOException
-
shortValue
- Specified by:
shortValue
in interfaceXContentParser
- Throws:
IOException
-
intValue
- Specified by:
intValue
in interfaceXContentParser
- Throws:
IOException
-
longValue
- Specified by:
longValue
in interfaceXContentParser
- Throws:
IOException
-
floatValue
- Specified by:
floatValue
in interfaceXContentParser
- Throws:
IOException
-
doubleValue
- Specified by:
doubleValue
in interfaceXContentParser
- Throws:
IOException
-
isBooleanValue
- Specified by:
isBooleanValue
in interfaceXContentParser
- Returns:
- true iff the current value is either boolean (
true
orfalse
) or one of "false", "true". - Throws:
IOException
-
booleanValue
- Specified by:
booleanValue
in interfaceXContentParser
- Throws:
IOException
-
binaryValue
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:
IOException
-
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
Description copied from interface:XContentParser
Parse an object by name.- Specified by:
namedObject
in interfaceXContentParser
- Throws:
IOException
-
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
Description copied from interface:XContentParser
The callback to notify when parsing encounters a deprecated field.- Specified by:
getDeprecationHandler
in interfaceXContentParser
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-