Skip to content

Commit

Permalink
handle cases when the body is not set in thrift
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Oct 13, 2010
1 parent 9077bb6 commit 1f4aa5d
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.thrift;

import org.elasticsearch.common.Bytes;
import org.elasticsearch.common.Unicode;
import org.elasticsearch.common.collect.ImmutableSet;
import org.elasticsearch.rest.support.AbstractRestRequest;
Expand Down Expand Up @@ -87,18 +88,30 @@ public ThriftRestRequest(org.elasticsearch.thrift.RestRequest request) {
}

@Override public byte[] contentByteArray() {
if (!request.isSetBody()) {
return Bytes.EMPTY_ARRAY;
}
return request.getBody().array();
}

@Override public int contentByteArrayOffset() {
if (!request.isSetBody()) {
return 0;
}
return request.getBody().arrayOffset();
}

@Override public int contentLength() {
if (!request.isSetBody()) {
return 0;
}
return request.getBody().remaining();
}

@Override public String contentAsString() {
if (!request.isSetBody()) {
return "";
}
return Unicode.fromBytes(contentByteArray(), contentByteArrayOffset(), contentLength());
}

Expand Down

0 comments on commit 1f4aa5d

Please sign in to comment.