use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class JRTClientConfigRequestV3 method getNewPayload.
@Override
public Payload getNewPayload() {
CompressionInfo compressionInfo = getResponseData().getCompressionInfo();
Utf8Array payload = new Utf8Array(request.returnValues().get(1).asData());
return Payload.from(payload, compressionInfo);
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class Payload method withCompression.
/**
* Returns a copy of this payload where the data is compressed using the given compression
*/
public Payload withCompression(CompressionType requestedCompression) {
CompressionType responseCompression = compressionInfo.getCompressionType();
if (requestedCompression == CompressionType.UNCOMPRESSED && responseCompression == CompressionType.LZ4) {
byte[] buffer = new byte[compressionInfo.getUncompressedSize()];
compressor.decompress(data.getBytes(), buffer);
Utf8Array data = new Utf8Array(buffer);
CompressionInfo info = CompressionInfo.create(CompressionType.UNCOMPRESSED, compressionInfo.getUncompressedSize());
return Payload.from(data, info);
} else if (requestedCompression == CompressionType.LZ4 && responseCompression == CompressionType.UNCOMPRESSED) {
Utf8Array data = new Utf8Array(compressor.compress(this.data.getBytes()));
CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, this.data.getByteLength());
return Payload.from(data, info);
} else {
return Payload.from(data, compressionInfo);
}
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class PayloadTest method testEquals.
@Test
public void testEquals() {
final String foo1 = "foo 1";
final String foo2 = "foo 2";
Payload a = Payload.from(foo1);
Payload b = Payload.from(foo1);
Payload c = Payload.from(foo2);
Slime slime = new Slime();
slime.setString(foo1);
Payload d = Payload.from(new ConfigPayload(slime));
slime.setString(foo1);
Payload e = Payload.from(new ConfigPayload(slime));
slime.setString("foo 2");
Payload f = Payload.from(new ConfigPayload(slime));
Payload g = null;
Payload h = null;
Payload i = null;
Payload j = null;
try {
g = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed());
h = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed());
LZ4PayloadCompressor compressor = new LZ4PayloadCompressor();
CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, foo2.length());
Utf8Array compressed = new Utf8Array(compressor.compress(foo2.getBytes()));
i = Payload.from(compressed, info);
j = Payload.from(compressed, info);
} catch (UnsupportedEncodingException e1) {
fail();
}
new EqualsTester().addEqualityGroup(a, b, g, h).addEqualityGroup(c).addEqualityGroup(d, e).addEqualityGroup(f).addEqualityGroup(i, j).testEquals();
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class LZ4ConfigResponseFactory method createResponse.
@Override
public ConfigResponse createResponse(ConfigPayload payload, InnerCNode defFile, long generation) {
Utf8Array rawPayload = payload.toUtf8Array(true);
String configMd5 = ConfigUtils.getMd5(rawPayload);
CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, rawPayload.getByteLength());
Utf8Array compressed = new Utf8Array(compressor.compress(rawPayload.getBytes()));
return new SlimeConfigResponse(compressed, defFile, generation, configMd5, info);
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class UncompressedConfigResponseFactory method createResponse.
@Override
public ConfigResponse createResponse(ConfigPayload payload, InnerCNode defFile, long generation) {
Utf8Array rawPayload = payload.toUtf8Array(true);
String configMd5 = ConfigUtils.getMd5(rawPayload);
CompressionInfo info = CompressionInfo.create(CompressionType.UNCOMPRESSED, rawPayload.getByteLength());
return new SlimeConfigResponse(rawPayload, defFile, generation, configMd5, info);
}
Aggregations