Java Code Examples for org.elasticsearch.common.bytes.BytesArray#EMPTY

The following examples show how to use org.elasticsearch.common.bytes.BytesArray#EMPTY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalRestRequest.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: NettyHttpRequest.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: CrateThrowableRestResponse.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 4
Source File: BytesRestResponse.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
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));
    }
}
 
Example 5
Source File: StreamInput.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: StreamInput.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source File: BytesRestResponse.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public BytesRestResponse(RestStatus status) {
    this(status, TEXT_CONTENT_TYPE, BytesArray.EMPTY);
}