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/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.
  • Constructor Details

    • XContentSubParser

      public XContentSubParser​(XContentParser parser)
  • Method Details

    • contentType

      public XContentType contentType()
      Specified by:
      contentType in interface XContentParser
    • nextToken

      public XContentParser.Token nextToken() throws java.io.IOException
      Specified by:
      nextToken in interface XContentParser
      Throws:
      java.io.IOException
    • skipChildren

      public void skipChildren() throws java.io.IOException
      Specified by:
      skipChildren in interface XContentParser
      Throws:
      java.io.IOException
    • currentToken

      public XContentParser.Token currentToken()
      Specified by:
      currentToken in interface XContentParser
    • currentName

      public java.lang.String currentName() throws java.io.IOException
      Specified by:
      currentName in interface XContentParser
      Throws:
      java.io.IOException
    • map

      public java.util.Map<java.lang.String,​java.lang.Object> map() throws java.io.IOException
      Specified by:
      map in interface XContentParser
      Throws:
      java.io.IOException
    • mapOrdered

      public java.util.Map<java.lang.String,​java.lang.Object> mapOrdered() throws java.io.IOException
      Specified by:
      mapOrdered in interface XContentParser
      Throws:
      java.io.IOException
    • mapStrings

      public java.util.Map<java.lang.String,​java.lang.String> mapStrings() throws java.io.IOException
      Specified by:
      mapStrings in interface XContentParser
      Throws:
      java.io.IOException
    • map

      public <T> java.util.Map<java.lang.String,​T> map​(java.util.function.Supplier<java.util.Map<java.lang.String,​T>> mapFactory, org.elasticsearch.common.CheckedFunction<XContentParser,​T,​java.io.IOException> mapValueParser) throws java.io.IOException
      Description copied from interface: XContentParser
      Returns an instance of Map holding parsed map. Serves as a replacement for the "map", "mapOrdered" and "mapStrings" methods above.
      Specified by:
      map in interface XContentParser
      Type Parameters:
      T - map value type
      Parameters:
      mapFactory - factory for creating new Map objects
      mapValueParser - parser for parsing a single map value
      Returns:
      Map object
      Throws:
      java.io.IOException
    • list

      public java.util.List<java.lang.Object> list() throws java.io.IOException
      Specified by:
      list in interface XContentParser
      Throws:
      java.io.IOException
    • listOrderedMap

      public java.util.List<java.lang.Object> listOrderedMap() throws java.io.IOException
      Specified by:
      listOrderedMap in interface XContentParser
      Throws:
      java.io.IOException
    • text

      public java.lang.String text() throws java.io.IOException
      Specified by:
      text in interface XContentParser
      Throws:
      java.io.IOException
    • textOrNull

      public java.lang.String textOrNull() throws java.io.IOException
      Specified by:
      textOrNull in interface XContentParser
      Throws:
      java.io.IOException
    • charBufferOrNull

      public java.nio.CharBuffer charBufferOrNull() throws java.io.IOException
      Specified by:
      charBufferOrNull in interface XContentParser
      Throws:
      java.io.IOException
    • charBuffer

      public java.nio.CharBuffer charBuffer() throws java.io.IOException
      Description copied from interface: XContentParser
      Returns a CharBuffer holding UTF-8 bytes. This method should be used to read text only binary content should be read through XContentParser.binaryValue()
      Specified by:
      charBuffer in interface XContentParser
      Throws:
      java.io.IOException
    • objectText

      public java.lang.Object objectText() throws java.io.IOException
      Specified by:
      objectText in interface XContentParser
      Throws:
      java.io.IOException
    • objectBytes

      public java.lang.Object objectBytes() throws java.io.IOException
      Specified by:
      objectBytes in interface XContentParser
      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 interface XContentParser
    • textCharacters

      public char[] textCharacters() throws java.io.IOException
      Specified by:
      textCharacters in interface XContentParser
      Throws:
      java.io.IOException
    • textLength

      public int textLength() throws java.io.IOException
      Specified by:
      textLength in interface XContentParser
      Throws:
      java.io.IOException
    • textOffset

      public int textOffset() throws java.io.IOException
      Specified by:
      textOffset in interface XContentParser
      Throws:
      java.io.IOException
    • numberValue

      public java.lang.Number numberValue() throws java.io.IOException
      Specified by:
      numberValue in interface XContentParser
      Throws:
      java.io.IOException
    • numberType

      public XContentParser.NumberType numberType() throws java.io.IOException
      Specified by:
      numberType in interface XContentParser
      Throws:
      java.io.IOException
    • shortValue

      public short shortValue​(boolean coerce) throws java.io.IOException
      Specified by:
      shortValue in interface XContentParser
      Throws:
      java.io.IOException
    • intValue

      public int intValue​(boolean coerce) throws java.io.IOException
      Specified by:
      intValue in interface XContentParser
      Throws:
      java.io.IOException
    • longValue

      public long longValue​(boolean coerce) throws java.io.IOException
      Specified by:
      longValue in interface XContentParser
      Throws:
      java.io.IOException
    • floatValue

      public float floatValue​(boolean coerce) throws java.io.IOException
      Specified by:
      floatValue in interface XContentParser
      Throws:
      java.io.IOException
    • doubleValue

      public double doubleValue​(boolean coerce) throws java.io.IOException
      Specified by:
      doubleValue in interface XContentParser
      Throws:
      java.io.IOException
    • shortValue

      public short shortValue() throws java.io.IOException
      Specified by:
      shortValue in interface XContentParser
      Throws:
      java.io.IOException
    • intValue

      public int intValue() throws java.io.IOException
      Specified by:
      intValue in interface XContentParser
      Throws:
      java.io.IOException
    • longValue

      public long longValue() throws java.io.IOException
      Specified by:
      longValue in interface XContentParser
      Throws:
      java.io.IOException
    • floatValue

      public float floatValue() throws java.io.IOException
      Specified by:
      floatValue in interface XContentParser
      Throws:
      java.io.IOException
    • doubleValue

      public double doubleValue() throws java.io.IOException
      Specified by:
      doubleValue in interface XContentParser
      Throws:
      java.io.IOException
    • isBooleanValue

      public boolean isBooleanValue() throws java.io.IOException
      Specified by:
      isBooleanValue in interface XContentParser
      Returns:
      true iff the current value is either boolean (true or false) or one of "false", "true".
      Throws:
      java.io.IOException
    • booleanValue

      public boolean booleanValue() throws java.io.IOException
      Specified by:
      booleanValue in interface XContentParser
      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 their String 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 interface XContentParser
      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 interface XContentParser
      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 interface XContentParser
      Throws:
      java.io.IOException
    • getXContentRegistry

      public NamedXContentRegistry getXContentRegistry()
      Description copied from interface: XContentParser
      The registry used to resolve XContentParser.namedObject(Class, String, Object). Use this when building a sub-parser from this parser.
      Specified by:
      getXContentRegistry in interface XContentParser
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface XContentParser
    • getDeprecationHandler

      public DeprecationHandler getDeprecationHandler()
      Description copied from interface: XContentParser
      The callback to notify when parsing encounters a deprecated field.
      Specified by:
      getDeprecationHandler in interface XContentParser
    • close

      public void close() throws java.io.IOException
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface java.io.Closeable
      Throws:
      java.io.IOException