Class XContentFactory

java.lang.Object
org.opensearch.common.xcontent.XContentFactory

public class XContentFactory extends Object
A one stop to use XContent and XContentBuilder.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.opensearch.core.xcontent.XContentBuilder
    Returns a content builder using CBOR format (XContentType.CBOR.
    static org.opensearch.core.xcontent.XContentBuilder
    Constructs a new cbor builder that will output the result into the provided output stream.
    static org.opensearch.core.xcontent.XContentBuilder
    Returns a binary content builder for the provided content type.
    static org.opensearch.core.xcontent.XContentBuilder
    Constructs a xcontent builder that will output the result into the provided output stream.
    static org.opensearch.core.xcontent.XContentBuilder
    contentBuilder(org.opensearch.core.xcontent.MediaType type)
    Returns a binary content builder for the provided media type.
    static org.opensearch.core.xcontent.XContentBuilder
    Returns a content builder using JSON format (XContentType.JSON.
    static org.opensearch.core.xcontent.XContentBuilder
    Constructs a new json builder that will output the result into the provided output stream.
    static org.opensearch.core.xcontent.XContentBuilder
    Returns a content builder using SMILE format (XContentType.SMILE.
    static org.opensearch.core.xcontent.XContentBuilder
    Constructs a new json builder that will output the result into the provided output stream.
    static org.opensearch.core.xcontent.XContent
    xContent(byte[] data)
    Deprecated.
    the content type should not be guessed except for few cases where we effectively don't know the content type.
    static org.opensearch.core.xcontent.XContent
    xContent(byte[] data, int offset, int length)
    Deprecated.
    guessing the content type should not be needed ideally.
    static org.opensearch.core.xcontent.XContent
    Deprecated.
    the content type should not be guessed except for few cases where we effectively don't know the content type.
    static org.opensearch.core.xcontent.XContent
    xContent(org.opensearch.core.xcontent.MediaType type)
    Returns the XContent for the provided content type.
    xContentType(byte[] bytes)
    Deprecated.
    the content type should not be guessed except for few cases where we effectively don't know the content type.
    xContentType(byte[] bytes, int offset, int length)
    Deprecated.
    the content type should not be guessed except for few cases where we effectively don't know the content type.
    Deprecated.
    the content type should not be guessed except for few cases where we effectively don't know the content type.
    Deprecated.
    the content type should not be guessed except for few cases where we effectively don't know the content type.
    static org.opensearch.core.xcontent.XContentBuilder
    Returns a content builder using YAML format (XContentType.YAML.
    static org.opensearch.core.xcontent.XContentBuilder
    Constructs a new yaml builder that will output the result into the provided output stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • XContentFactory

      public XContentFactory()
  • Method Details

    • jsonBuilder

      public static org.opensearch.core.xcontent.XContentBuilder jsonBuilder() throws IOException
      Returns a content builder using JSON format (XContentType.JSON.
      Throws:
      IOException
    • jsonBuilder

      public static org.opensearch.core.xcontent.XContentBuilder jsonBuilder(OutputStream os) throws IOException
      Constructs a new json builder that will output the result into the provided output stream.
      Throws:
      IOException
    • smileBuilder

      public static org.opensearch.core.xcontent.XContentBuilder smileBuilder() throws IOException
      Returns a content builder using SMILE format (XContentType.SMILE.
      Throws:
      IOException
    • smileBuilder

      public static org.opensearch.core.xcontent.XContentBuilder smileBuilder(OutputStream os) throws IOException
      Constructs a new json builder that will output the result into the provided output stream.
      Throws:
      IOException
    • yamlBuilder

      public static org.opensearch.core.xcontent.XContentBuilder yamlBuilder() throws IOException
      Returns a content builder using YAML format (XContentType.YAML.
      Throws:
      IOException
    • yamlBuilder

      public static org.opensearch.core.xcontent.XContentBuilder yamlBuilder(OutputStream os) throws IOException
      Constructs a new yaml builder that will output the result into the provided output stream.
      Throws:
      IOException
    • cborBuilder

      public static org.opensearch.core.xcontent.XContentBuilder cborBuilder() throws IOException
      Returns a content builder using CBOR format (XContentType.CBOR.
      Throws:
      IOException
    • cborBuilder

      public static org.opensearch.core.xcontent.XContentBuilder cborBuilder(OutputStream os) throws IOException
      Constructs a new cbor builder that will output the result into the provided output stream.
      Throws:
      IOException
    • contentBuilder

      public static org.opensearch.core.xcontent.XContentBuilder contentBuilder(XContentType type, OutputStream outputStream) throws IOException
      Constructs a xcontent builder that will output the result into the provided output stream.
      Throws:
      IOException
    • contentBuilder

      public static org.opensearch.core.xcontent.XContentBuilder contentBuilder(org.opensearch.core.xcontent.MediaType type) throws IOException
      Returns a binary content builder for the provided media type.
      Throws:
      IOException
    • contentBuilder

      public static org.opensearch.core.xcontent.XContentBuilder contentBuilder(XContentType type) throws IOException
      Returns a binary content builder for the provided content type.
      Throws:
      IOException
    • xContent

      public static org.opensearch.core.xcontent.XContent xContent(org.opensearch.core.xcontent.MediaType type)
      Returns the XContent for the provided content type.
    • xContentType

      @Deprecated public static XContentType xContentType(CharSequence content)
      Deprecated.
      the content type should not be guessed except for few cases where we effectively don't know the content type. The REST layer should move to reading the Content-Type header instead. There are other places where auto-detection may be needed. This method is deprecated to prevent usages of it from spreading further without specific reasons.
      Guesses the content type based on the provided char sequence.
    • xContent

      @Deprecated public static org.opensearch.core.xcontent.XContent xContent(CharSequence content)
      Deprecated.
      the content type should not be guessed except for few cases where we effectively don't know the content type. The REST layer should move to reading the Content-Type header instead. There are other places where auto-detection may be needed. This method is deprecated to prevent usages of it from spreading further without specific reasons.
      Guesses the content (type) based on the provided char sequence and returns the corresponding XContent
    • xContent

      @Deprecated public static org.opensearch.core.xcontent.XContent xContent(byte[] data)
      Deprecated.
      the content type should not be guessed except for few cases where we effectively don't know the content type. The REST layer should move to reading the Content-Type header instead. There are other places where auto-detection may be needed. This method is deprecated to prevent usages of it from spreading further without specific reasons.
      Guesses the content type based on the provided bytes and returns the corresponding XContent
    • xContent

      @Deprecated public static org.opensearch.core.xcontent.XContent xContent(byte[] data, int offset, int length)
      Deprecated.
      guessing the content type should not be needed ideally. We should rather know the content type upfront or read it from headers. Till we fixed the REST layer to read the Content-Type header, that should be the only place where guessing is needed.
      Guesses the content type based on the provided bytes and returns the corresponding XContent
    • xContentType

      @Deprecated public static XContentType xContentType(InputStream si) throws IOException
      Deprecated.
      the content type should not be guessed except for few cases where we effectively don't know the content type. The REST layer should move to reading the Content-Type header instead. There are other places where auto-detection may be needed. This method is deprecated to prevent usages of it from spreading further without specific reasons.
      Guesses the content type based on the provided input stream without consuming it.
      Throws:
      IOException
    • xContentType

      @Deprecated public static XContentType xContentType(byte[] bytes)
      Deprecated.
      the content type should not be guessed except for few cases where we effectively don't know the content type. The REST layer should move to reading the Content-Type header instead. There are other places where auto-detection may be needed. This method is deprecated to prevent usages of it from spreading further without specific reasons.
      Guesses the content type based on the provided bytes.
    • xContentType

      @Deprecated public static XContentType xContentType(byte[] bytes, int offset, int length)
      Deprecated.
      the content type should not be guessed except for few cases where we effectively don't know the content type. The REST layer should move to reading the Content-Type header instead. There are other places where auto-detection may be needed. This method is deprecated to prevent usages of it from spreading further without specific reasons.
      Guesses the content type based on the provided bytes.