org.elasticsearch.common.Strings.createBuilder()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(3.3k)|赞(0)|评价(0)|浏览(117)

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

Strings.createBuilder介绍

暂无

代码示例

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

/**
 * Return a {@link String} that is the json representation of the provided {@link ToXContent}.
 * Wraps the output into an anonymous object if needed. Allows to control whether the outputted
 * json needs to be pretty printed and human readable.
 *
 */
public static String toString(ToXContent toXContent, boolean pretty, boolean human) {
  try {
    XContentBuilder builder = createBuilder(pretty, human);
    if (toXContent.isFragment()) {
      builder.startObject();
    }
    toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
    if (toXContent.isFragment()) {
      builder.endObject();
    }
    return toString(builder);
  } catch (IOException e) {
    try {
      XContentBuilder builder = createBuilder(pretty, human);
      builder.startObject();
      builder.field("error", "error building toString out of XContent: " + e.getMessage());
      builder.field("stack_trace", ExceptionsHelper.stackTrace(e));
      builder.endObject();
      return toString(builder);
    } catch (IOException e2) {
      throw new ElasticsearchException("cannot generate error message for deserialization", e);
    }
  }
}

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

/**
 * Return a {@link String} that is the json representation of the provided {@link ToXContent}.
 * Wraps the output into an anonymous object if needed. Allows to control whether the outputted
 * json needs to be pretty printed and human readable.
 *
 */
public static String toString(ToXContent toXContent, boolean pretty, boolean human) {
  try {
    XContentBuilder builder = createBuilder(pretty, human);
    if (toXContent.isFragment()) {
      builder.startObject();
    }
    toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
    if (toXContent.isFragment()) {
      builder.endObject();
    }
    return toString(builder);
  } catch (IOException e) {
    try {
      XContentBuilder builder = createBuilder(pretty, human);
      builder.startObject();
      builder.field("error", "error building toString out of XContent: " + e.getMessage());
      builder.field("stack_trace", ExceptionsHelper.stackTrace(e));
      builder.endObject();
      return toString(builder);
    } catch (IOException e2) {
      throw new ElasticsearchException("cannot generate error message for deserialization", e);
    }
  }
}

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

/**
 * Return a {@link String} that is the json representation of the provided {@link ToXContent}.
 * Wraps the output into an anonymous object if needed. Allows to control whether the outputted
 * json needs to be pretty printed and human readable.
 *
 */
public static String toString(ToXContent toXContent, boolean pretty, boolean human) {
  try {
    XContentBuilder builder = createBuilder(pretty, human);
    if (toXContent.isFragment()) {
      builder.startObject();
    }
    toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
    if (toXContent.isFragment()) {
      builder.endObject();
    }
    return toString(builder);
  } catch (IOException e) {
    try {
      XContentBuilder builder = createBuilder(pretty, human);
      builder.startObject();
      builder.field("error", "error building toString out of XContent: " + e.getMessage());
      builder.field("stack_trace", ExceptionsHelper.stackTrace(e));
      builder.endObject();
      return toString(builder);
    } catch (IOException e2) {
      throw new ElasticsearchException("cannot generate error message for deserialization", e);
    }
  }
}

相关文章

微信公众号

最新文章

更多