本文整理汇总了Java中org.elasticsearch.common.bytes.BytesArray.EMPTY属性的典型用法代码示例。如果您正苦于以下问题:Java BytesArray.EMPTY属性的具体用法?Java BytesArray.EMPTY怎么用?Java BytesArray.EMPTY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.elasticsearch.common.bytes.BytesArray
的用法示例。
在下文中一共展示了BytesArray.EMPTY属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testXContentBuilderClosedInBuildResponse
public void testXContentBuilderClosedInBuildResponse() throws Exception {
AtomicReference<XContentBuilder> builderAtomicReference = new AtomicReference<>();
RestBuilderListener<TransportResponse.Empty> builderListener =
new RestBuilderListener<Empty>(new FakeRestChannel(new FakeRestRequest(), randomBoolean(), 1)) {
@Override
public RestResponse buildResponse(Empty empty, XContentBuilder builder) throws Exception {
builderAtomicReference.set(builder);
builder.close();
return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
}
};
builderListener.buildResponse(Empty.INSTANCE);
assertNotNull(builderAtomicReference.get());
assertTrue(builderAtomicReference.get().generator().isClosed());
}
示例2: testXContentBuilderNotClosedInBuildResponseAssertionsDisabled
public void testXContentBuilderNotClosedInBuildResponseAssertionsDisabled() throws Exception {
AtomicReference<XContentBuilder> builderAtomicReference = new AtomicReference<>();
RestBuilderListener<TransportResponse.Empty> builderListener =
new RestBuilderListener<Empty>(new FakeRestChannel(new FakeRestRequest(), randomBoolean(), 1)) {
@Override
public RestResponse buildResponse(Empty empty, XContentBuilder builder) throws Exception {
builderAtomicReference.set(builder);
return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
}
@Override
boolean assertBuilderClosed(XContentBuilder xContentBuilder) {
// don't check the actual builder being closed so we can test auto close
return true;
}
};
builderListener.buildResponse(Empty.INSTANCE);
assertNotNull(builderAtomicReference.get());
assertTrue(builderAtomicReference.get().generator().isClosed());
}
示例3: LocalRestRequest
public LocalRestRequest(final String uri, final Method method) {
this.headers = new HashMap<>();
if (uri.startsWith("\"") && uri.endsWith("\"")) {
this.uri = uri.substring(1, uri.length()-1);
} else {
this.uri = uri;
}
this.method = method;
this.params = new HashMap<>();
this.content = BytesArray.EMPTY;
int pathEndPos = this.uri.indexOf('?');
if (pathEndPos < 0) {
this.rawPath = this.uri;
} else {
this.rawPath = this.uri.substring(0, pathEndPos);
RestUtils.decodeQueryString(this.uri, pathEndPos + 1, params);
}
}
示例4: NettyHttpRequest
public NettyHttpRequest(org.jboss.netty.handler.codec.http.HttpRequest request, Channel channel) {
this.request = request;
this.channel = channel;
this.params = new HashMap<>();
if (request.getContent().readable()) {
this.content = new ChannelBufferBytesReference(request.getContent());
} else {
this.content = BytesArray.EMPTY;
}
String uri = request.getUri();
int pathEndPos = uri.indexOf('?');
if (pathEndPos < 0) {
this.rawPath = uri;
} else {
this.rawPath = uri.substring(0, pathEndPos);
RestUtils.decodeQueryString(uri, pathEndPos + 1, params);
}
}
示例5: Netty4HttpRequest
Netty4HttpRequest(NamedXContentRegistry xContentRegistry, FullHttpRequest request, Channel channel) {
super(xContentRegistry, request.uri(), new HttpHeadersMap(request.headers()));
this.request = request;
this.channel = channel;
if (request.content().isReadable()) {
this.content = Netty4Utils.toBytesReference(request.content());
} else {
this.content = BytesArray.EMPTY;
}
}
示例6: BytesRestResponse
public BytesRestResponse(RestChannel channel, RestStatus status, Exception e) throws IOException {
this.status = status;
if (channel.request().method() == RestRequest.Method.HEAD) {
this.content = BytesArray.EMPTY;
this.contentType = TEXT_CONTENT_TYPE;
} else {
try (XContentBuilder builder = build(channel, status, e)) {
this.content = builder.bytes();
this.contentType = builder.contentType().mediaType();
}
}
if (e instanceof ElasticsearchException) {
copyHeaders(((ElasticsearchException) e));
}
}
示例7: readBytesReference
/**
* Reads a bytes reference from this stream, might hold an actual reference to the underlying
* bytes of the stream.
*/
public BytesReference readBytesReference(int length) throws IOException {
if (length == 0) {
return BytesArray.EMPTY;
}
byte[] bytes = new byte[length];
readBytes(bytes, 0, length);
return new BytesArray(bytes, 0, length);
}
示例8: testXContentBuilderNotClosedInBuildResponseAssertionsEnabled
public void testXContentBuilderNotClosedInBuildResponseAssertionsEnabled() throws Exception {
assumeTrue("tests are not being run with assertions", RestBuilderListener.class.desiredAssertionStatus());
RestBuilderListener<TransportResponse.Empty> builderListener =
new RestBuilderListener<Empty>(new FakeRestChannel(new FakeRestRequest(), randomBoolean(), 1)) {
@Override
public RestResponse buildResponse(Empty empty, XContentBuilder builder) throws Exception {
return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
}
};
AssertionError error = expectThrows(AssertionError.class, () -> builderListener.buildResponse(Empty.INSTANCE));
assertEquals("callers should ensure the XContentBuilder is closed themselves", error.getMessage());
}
示例9: CrateThrowableRestResponse
public CrateThrowableRestResponse(RestChannel channel, Throwable t) throws IOException {
status = (t instanceof ElasticsearchException) ?
((ElasticsearchException) t).status() :
RestStatus.INTERNAL_SERVER_ERROR;
if (channel.request().method() == RestRequest.Method.HEAD) {
this.content = BytesArray.EMPTY;
this.contentType = BytesRestResponse.TEXT_CONTENT_TYPE;
} else {
XContentBuilder builder = convert(channel, t);
this.content = builder.bytes();
this.contentType = builder.contentType().restContentType();
}
}
示例10: BytesRestResponse
public BytesRestResponse(RestChannel channel, RestStatus status, Throwable t) throws IOException {
this.status = status;
if (channel.request().method() == RestRequest.Method.HEAD) {
this.content = BytesArray.EMPTY;
this.contentType = TEXT_CONTENT_TYPE;
} else {
XContentBuilder builder = convert(channel, status, t);
this.content = builder.bytes();
this.contentType = builder.contentType().restContentType();
}
if (t instanceof ElasticsearchException) {
copyHeaders(((ElasticsearchException) t));
}
}