diff --git a/src/main/java/org/elasticsearch/common/BytesHolder.java b/src/main/java/org/elasticsearch/common/BytesHolder.java index c95960c7739..3875f832768 100644 --- a/src/main/java/org/elasticsearch/common/BytesHolder.java +++ b/src/main/java/org/elasticsearch/common/BytesHolder.java @@ -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); diff --git a/src/main/java/org/elasticsearch/index/get/GetResult.java b/src/main/java/org/elasticsearch/index/get/GetResult.java index ef15d4089be..b8d9f8f404e 100644 --- a/src/main/java/org/elasticsearch/index/get/GetResult.java +++ b/src/main/java/org/elasticsearch/index/get/GetResult.java @@ -170,8 +170,7 @@ public class GetResult implements Streamable, Iterable, 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, 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, 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 {