org.elasticsearch.common.xcontent.XContentBuilder.<init>()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中org.elasticsearch.common.xcontent.XContentBuilder.<init>()方法的一些代码示例,展示了XContentBuilder.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XContentBuilder.<init>()方法的具体详情如下:
包路径:org.elasticsearch.common.xcontent.XContentBuilder
类名称:XContentBuilder
方法名:<init>

XContentBuilder.<init>介绍

[英]Constructs a new builder using the provided xcontent and an OutputStream. Make sure to call #close() when the builder is done with.
[中]使用提供的xcontent和OutputStream构造一个新的生成器。确保在生成器完成后调用#close()。

代码示例

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

public static XContentBuilder restContentBuilder(RestRequest request, @Nullable BytesReference autoDetectSource) throws IOException {
  XContentType contentType = XContentType.fromRestContentType(request.param("format", request.header("Content-Type")));
  if (contentType == null) {
    // try and guess it from the auto detect source
    if (autoDetectSource != null) {
      contentType = XContentFactory.xContentType(autoDetectSource);
    }
  }
  if (contentType == null) {
    // default to JSON
    contentType = XContentType.JSON;
  }
  XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), new BytesStreamOutput());
  if (request.paramAsBoolean("pretty", false)) {
    builder.prettyPrint().lfAtEnd();
  }
  builder.humanReadable(request.paramAsBoolean("human", builder.humanReadable()));
  String casing = request.param("case");
  if (casing != null && "camelCase".equals(casing)) {
    builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE);
  } else {
    // we expect all REST interfaces to write results in underscore casing, so
    // no need for double casing
    builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE);
  }
  return builder;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public String toString() {
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XContentBuilder builder = new XContentBuilder(JsonXContent.jsonXContent, baos);
    toXContent(builder, ToXContent.EMPTY_PARAMS, false);
    return Strings.toString(builder);
  } catch (IOException e) {
    throw new IllegalStateException(e); //should not be possible here
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

new XContentBuilder(XContentFactory.xContent(responseContentType), unclosableOutputStream, includes, excludes);
if (pretty) {
  builder.prettyPrint().lfAtEnd();

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  boolean includeDefaults = params.paramAsBoolean("include_defaults", false);
  if (!includeDefaults) {
    // simulate the generation to make sure we don't add unnecessary content if all is default
    // if all are defaults, no need to write it at all - generating is twice is ok though
    BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(0);
    XContentBuilder b =  new XContentBuilder(builder.contentType().xContent(), bytesStreamOutput);
    b.startObject().flush();
    long pos = bytesStreamOutput.position();
    innerToXContent(b, false);
    b.flush();
    if (pos == bytesStreamOutput.position()) {
      return builder;
    }
  }
  builder.startObject(CONTENT_TYPE);
  innerToXContent(builder, includeDefaults);
  builder.endObject();
  return builder;
}

代码示例来源:origin: org.elasticsearch/elasticsearch-x-content

/**
 * Constructs a new json builder that will output the result into the provided output stream.
 */
public static XContentBuilder jsonBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(JsonXContent.jsonXContent, os);
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Constructs a new json builder that will output the result into the provided output stream.
 */
public static XContentBuilder smileBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(SmileXContent.smileXContent, os);
}

代码示例来源:origin: org.elasticsearch/elasticsearch-x-content

/**
 * Constructs a new json builder that will output the result into the provided output stream.
 */
public static XContentBuilder smileBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(SmileXContent.smileXContent, os);
}

代码示例来源:origin: org.elasticsearch/elasticsearch-x-content

/**
 * Constructs a new yaml builder that will output the result into the provided output stream.
 */
public static XContentBuilder yamlBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(YamlXContent.yamlXContent, os);
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Constructs a new json builder that will output the result into the provided output stream.
 */
public static XContentBuilder jsonBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(JsonXContent.jsonXContent, os);
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Constructs a new json builder that will output the result into the provided output stream.
 */
public static XContentBuilder smileBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(SmileXContent.smileXContent, os);
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Constructs a new yaml builder that will output the result into the provided output stream.
 */
public static XContentBuilder yamlBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(YamlXContent.yamlXContent, os);
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Constructs a new cbor builder that will output the result into the provided output stream.
 */
public static XContentBuilder cborBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(CborXContent.cborXContent, os);
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Constructs a new cbor builder that will output the result into the provided output stream.
 */
public static XContentBuilder cborBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(CborXContent.cborXContent, os);
}

代码示例来源:origin: org.elasticsearch/elasticsearch-x-content

/**
 * Constructs a new cbor builder that will output the result into the provided output stream.
 */
public static XContentBuilder cborBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(CborXContent.cborXContent, os);
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Constructs a new yaml builder that will output the result into the provided output stream.
 */
public static XContentBuilder yamlBuilder(OutputStream os) throws IOException {
  return new XContentBuilder(YamlXContent.yamlXContent, os);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

final int initialCapacity = Math.min(1024, sourceAsBytes.length());
BytesStreamOutput streamOutput = new BytesStreamOutput(initialCapacity);
try (XContentBuilder builder = new XContentBuilder(sourceContentType.xContent(), streamOutput)) {
  builder.value(value);
  sourceFilteredAsBytes = BytesReference.bytes(builder);

代码示例来源:origin: org.elasticsearch/elasticsearch

final int initialCapacity = nestedHit ? 1024 : Math.min(1024, source.internalSourceRef().length());
BytesStreamOutput streamOutput = new BytesStreamOutput(initialCapacity);
XContentBuilder builder = new XContentBuilder(source.sourceContentType().xContent(), streamOutput);
if (value != null) {
  builder.value(value);

代码示例来源:origin: apache/servicemix-bundles

@Override
public String toString() {
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XContentBuilder builder = new XContentBuilder(JsonXContent.jsonXContent, baos);
    toXContent(builder, ToXContent.EMPTY_PARAMS, false);
    return Strings.toString(builder);
  } catch (IOException e) {
    throw new IllegalStateException(e); //should not be possible here
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

@Override
public String toString() {
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XContentBuilder builder = new XContentBuilder(JsonXContent.jsonXContent, baos);
    toXContent(builder, ToXContent.EMPTY_PARAMS, false);
    return Strings.toString(builder);
  } catch (IOException e) {
    throw new IllegalStateException(e); //should not be possible here
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Create a new {@link XContentBuilder} using the given {@link XContent} content.
 * <p>
 * The builder uses an internal {@link BytesStreamOutput} output stream to build the content.
 * </p>
 *
 * @param xContent the {@link XContent}
 * @return a new {@link XContentBuilder}
 * @throws IOException if an {@link IOException} occurs while building the content
 */
public static XContentBuilder builder(XContent xContent) throws IOException {
  return new XContentBuilder(xContent, new BytesStreamOutput());
}

相关文章

微信公众号

最新文章

更多