get / mget to read byte reference for the source

This commit is contained in:
Shay Banon 2012-01-08 15:47:32 +02:00
parent 7966716673
commit cf73e18146
2 changed files with 6 additions and 36 deletions

View File

@ -19,14 +19,9 @@
package org.elasticsearch.common;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.IOException;
import java.util.Arrays;
public class BytesHolder implements Streamable {
public class BytesHolder {
public static final BytesHolder EMPTY = new BytesHolder(Bytes.EMPTY_ARRAY, 0, 0);
@ -66,26 +61,6 @@ public class BytesHolder implements Streamable {
return length;
}
public static BytesHolder readBytesHolder(StreamInput in) throws IOException {
BytesHolder holder = new BytesHolder();
holder.readFrom(in);
return holder;
}
@Override
public void readFrom(StreamInput in) throws IOException {
offset = 0;
length = in.readVInt();
bytes = new byte[length];
in.readBytes(bytes, 0, length);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(length);
out.writeBytes(bytes, offset, length);
}
@Override
public boolean equals(Object obj) {
return bytesEquals((BytesHolder) obj);

View File

@ -170,8 +170,7 @@ public class GetResult implements Streamable, Iterable<GetField>, ToXContent {
public BytesHolder sourceRef() {
if (LZF.isCompressed(source.bytes(), source.offset(), source.length())) {
try {
// TODO decompress without doing an extra copy!
this.source = new BytesHolder(LZFDecoder.decode(source.copyBytes()));
this.source = new BytesHolder(LZFDecoder.decode(source.bytes(), source.offset(), source.length()));
} catch (IOException e) {
throw new ElasticSearchParseException("failed to decompress source", e);
}
@ -315,8 +314,9 @@ public class GetResult implements Streamable, Iterable<GetField>, ToXContent {
version = in.readLong();
exists = in.readBoolean();
if (exists) {
if (in.readBoolean()) {
source = BytesHolder.readBytesHolder(in);
source = in.readBytesReference();
if (source.length() == 0) {
source = null;
}
int size = in.readVInt();
if (size == 0) {
@ -339,12 +339,7 @@ public class GetResult implements Streamable, Iterable<GetField>, ToXContent {
out.writeLong(version);
out.writeBoolean(exists);
if (exists) {
if (source == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
source.writeTo(out);
}
out.writeBytesHolder(source);
if (fields == null) {
out.writeVInt(0);
} else {