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

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

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

XContentBuilder.close介绍

暂无

代码示例

代码示例来源:origin: floragunncom/search-guard

@Override
public void accept(RestChannel channel) throws Exception {
  XContentBuilder builder = channel.newBuilder();
  RestStatus restStatus = RestStatus.OK;
  BytesRestResponse response = null;
  try {
    
    
    String status = "UP";
    String message = null;
    builder.startObject();
    if ("strict".equalsIgnoreCase(mode) && registry.isInitialized() == false) {
      status = "DOWN";
      message = "Not initialized";
      restStatus = RestStatus.SERVICE_UNAVAILABLE;
    }
    builder.field("message", message);
    builder.field("mode", mode);
    builder.field("status", status);
    builder.endObject();
    response = new BytesRestResponse(restStatus, builder);
  } finally {
    builder.close();
  }
  
  
  channel.sendResponse(response);
}

代码示例来源:origin: floragunncom/search-guard

} finally {
  if(builder != null) {
    builder.close();

代码示例来源:origin: floragunncom/search-guard

} finally {
  if(builder != null) {
    builder.close();

代码示例来源:origin: floragunncom/search-guard

} finally {
  if(builder != null) {
    builder.close();

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

/**
 * Convert an {@link XContentBuilder} into a BytesReference. This method closes the builder,
 * so no further fields may be added.
 */
public static BytesReference bytes(XContentBuilder xContentBuilder) {
  xContentBuilder.close();
  OutputStream stream = xContentBuilder.getOutputStream();
  if (stream instanceof ByteArrayOutputStream) {
    return new BytesArray(((ByteArrayOutputStream) stream).toByteArray());
  } else {
    return ((BytesStream) stream).bytes();
  }
}

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

public AliasActions filter(QueryBuilder filter) {
  if (filter == null) {
    this.filter = null;
    return this;
  }
  try {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    filter.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.close();
    this.filter = Strings.toString(builder);
    return this;
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
  }
}

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

/**
 * Associates a filter to the alias
 */
public Alias filter(QueryBuilder filterBuilder) {
  if (filterBuilder == null) {
    this.filter = null;
    return this;
  }
  try {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    filterBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.close();
    this.filter = Strings.toString(builder);
    return this;
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
  }
}

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

/**
 * Writes the incompatible snapshot ids list to the `incompatible-snapshots` blob in the repository.
 *
 * Package private for testing.
 */
void writeIncompatibleSnapshots(RepositoryData repositoryData) throws IOException {
  assert isReadOnly() == false; // can not write to a read only repository
  final BytesReference bytes;
  try (BytesStreamOutput bStream = new BytesStreamOutput()) {
    try (StreamOutput stream = new OutputStreamStreamOutput(bStream)) {
      XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON, stream);
      repositoryData.incompatibleSnapshotsToXContent(builder, ToXContent.EMPTY_PARAMS);
      builder.close();
    }
    bytes = bStream.bytes();
  }
  // write the incompatible snapshots blob
  writeAtomic(INCOMPATIBLE_SNAPSHOTS_BLOB, bytes, false);
}

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

XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON, stream);
repositoryData.snapshotsToXContent(builder, ToXContent.EMPTY_PARAMS);
builder.close();

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

@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
  BytesReference originalSource = context.sourceToParse().source();
  BytesReference source = originalSource;
  if (enabled && fieldType().stored() && source != null) {
    // Percolate and tv APIs may not set the source and that is ok, because these APIs will not index any data
    if (filter != null) {
      // we don't update the context source if we filter, we want to keep it as is...
      Tuple<XContentType, Map<String, Object>> mapTuple =
        XContentHelper.convertToMap(source, true, context.sourceToParse().getXContentType());
      Map<String, Object> filteredSource = filter.apply(mapTuple.v2());
      BytesStreamOutput bStream = new BytesStreamOutput();
      XContentType contentType = mapTuple.v1();
      XContentBuilder builder = XContentFactory.contentBuilder(contentType, bStream).map(filteredSource);
      builder.close();
      source = bStream.bytes();
    }
    BytesRef ref = source.toBytesRef();
    fields.add(new StoredField(fieldType().name(), ref.bytes, ref.offset, ref.length));
  } else {
    source = null;
  }
  if (originalSource != null && source != originalSource && context.indexSettings().isSoftDeleteEnabled()) {
    // if we omitted source or modified it we add the _recovery_source to ensure we have it for ops based recovery
    BytesRef ref = originalSource.toBytesRef();
    fields.add(new StoredField(RECOVERY_SOURCE_NAME, ref.bytes, ref.offset, ref.length));
    fields.add(new NumericDocValuesField(RECOVERY_SOURCE_NAME, 1));
  }
 }

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

@Override
public BytesReference bytes() {
  close();
  return ((BytesStream) bos).bytes();
}

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

public BytesReference bytes() {
  close();
  return ((BytesStream) bos).bytes();
}

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

/**
 * Convert an {@link XContentBuilder} into a BytesReference. This method closes the builder,
 * so no further fields may be added.
 */
public static BytesReference bytes(XContentBuilder xContentBuilder) {
  xContentBuilder.close();
  OutputStream stream = xContentBuilder.getOutputStream();
  if (stream instanceof ByteArrayOutputStream) {
    return new BytesArray(((ByteArrayOutputStream) stream).toByteArray());
  } else {
    return ((BytesStream) stream).bytes();
  }
}

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

/**
 * Convert an {@link XContentBuilder} into a BytesReference. This method closes the builder,
 * so no further fields may be added.
 */
public static BytesReference bytes(XContentBuilder xContentBuilder) {
  xContentBuilder.close();
  OutputStream stream = xContentBuilder.getOutputStream();
  if (stream instanceof ByteArrayOutputStream) {
    return new BytesArray(((ByteArrayOutputStream) stream).toByteArray());
  } else {
    return ((BytesStream) stream).bytes();
  }
}

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

/**
 * Returns a string representation of the builder (only applicable for text based xcontent).
 */
public String string() throws IOException {
  close();
  BytesArray bytesArray = bytes().toBytesArray();
  return new String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length(), Charsets.UTF_8);
}

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

private static GeoPoint parseGeoPointString(String value) {
  try {
    XContentBuilder content = JsonXContent.contentBuilder();
    content.value(value);
    content.flush();
    content.close();
    try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
        THROW_UNSUPPORTED_OPERATION, ((ByteArrayOutputStream) content.getOutputStream()).toByteArray())) {
      parser.nextToken();
      return GeoUtils.parseGeoPoint(parser);
    }
  } catch (IOException e) {
    throw new IllegalArgumentException("Invalid value for geopoint: " + e.getMessage());
  }
}

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

public AliasAction filter(QueryBuilder queryBuilder) {
  if (queryBuilder == null) {
    this.filter = null;
    return this;
  }
  try {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    queryBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.close();
    this.filter = builder.string();
    return this;
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
  }
}

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

public AliasActions filter(QueryBuilder filter) {
  if (filter == null) {
    this.filter = null;
    return this;
  }
  try {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    filter.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.close();
    this.filter = builder.string();
    return this;
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
  }
}

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

public AliasActions filter(QueryBuilder filter) {
  if (filter == null) {
    this.filter = null;
    return this;
  }
  try {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    filter.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.close();
    this.filter = Strings.toString(builder);
    return this;
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
  }
}

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

public AliasActions filter(QueryBuilder filter) {
  if (filter == null) {
    this.filter = null;
    return this;
  }
  try {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    filter.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.close();
    this.filter = Strings.toString(builder);
    return this;
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
  }
}

相关文章

微信公众号

最新文章

更多