use of com.linkedin.r2.message.stream.entitystream.EntityStream in project rest.li by linkedin.
the class TestStreamingCompression method testCompressThenDecompress.
private void testCompressThenDecompress(StreamingCompressor compressor, byte[] origin) throws CompressionException, ExecutionException, InterruptedException {
ByteWriter writer = new ByteWriter(origin);
EntityStream uncompressedStream = EntityStreams.newEntityStream(writer);
EntityStream compressedStream = compressor.deflate(uncompressedStream);
EntityStream decompressedStream = compressor.inflate(compressedStream);
FutureCallback<byte[]> callback = new FutureCallback<>();
decompressedStream.setReader(new ByteReader(callback));
byte[] result = callback.get();
Assert.assertEquals(result, origin);
}
use of com.linkedin.r2.message.stream.entitystream.EntityStream in project rest.li by linkedin.
the class TestStreamingCompression method testCompress.
private void testCompress(StreamingCompressor compressor, byte[] uncompressed, byte[] compressed) throws CompressionException, ExecutionException, InterruptedException {
ByteWriter writer = new ByteWriter(uncompressed);
EntityStream uncompressedStream = EntityStreams.newEntityStream(writer);
EntityStream compressedStream = compressor.deflate(uncompressedStream);
FutureCallback<byte[]> callback = new FutureCallback<>();
compressedStream.setReader(new ByteReader(callback));
byte[] result = callback.get();
Assert.assertEquals(result, compressed);
}
use of com.linkedin.r2.message.stream.entitystream.EntityStream in project rest.li by linkedin.
the class DispatcherRequestFilter method onStreamRequest.
@Override
public void onStreamRequest(StreamRequest req, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<StreamRequest, StreamResponse> nextFilter) {
markOnRequestTimings(requestContext);
Connector connector = null;
try {
final AtomicBoolean responded = new AtomicBoolean(false);
TransportCallback<StreamResponse> callback = createStreamCallback(requestContext, nextFilter, responded);
connector = new Connector(responded, nextFilter, requestContext, wireAttrs);
req.getEntityStream().setReader(connector);
EntityStream newStream = EntityStreams.newEntityStream(connector);
_dispatcher.handleStreamRequest(req.builder().build(newStream), wireAttrs, requestContext, callback);
} catch (Exception e) {
nextFilter.onError(e, requestContext, new HashMap<>());
if (connector != null) {
connector.cancel();
}
}
}
use of com.linkedin.r2.message.stream.entitystream.EntityStream in project rest.li by linkedin.
the class TestStreamingCompression method testCompress.
private void testCompress(StreamingCompressor compressor, byte[] uncompressed, byte[] compressed) throws CompressionException, ExecutionException, InterruptedException {
ByteWriter writer = new ByteWriter(uncompressed);
EntityStream uncompressedStream = EntityStreams.newEntityStream(writer);
EntityStream compressedStream = compressor.deflate(uncompressedStream);
FutureCallback<byte[]> callback = new FutureCallback<>();
compressedStream.setReader(new ByteReader(callback));
byte[] result = callback.get();
Assert.assertEquals(result, compressed);
}
use of com.linkedin.r2.message.stream.entitystream.EntityStream in project rest.li by linkedin.
the class TestStreamingCompression method testDecompress.
private void testDecompress(StreamingCompressor compressor, byte[] uncompressed, byte[] compressed) throws CompressionException, ExecutionException, InterruptedException {
ByteWriter writer = new ByteWriter(compressed);
EntityStream compressedStream = EntityStreams.newEntityStream(writer);
EntityStream uncompressedStream = compressor.inflate(compressedStream);
FutureCallback<byte[]> callback = new FutureCallback<>();
uncompressedStream.setReader(new ByteReader(callback));
byte[] result = callback.get();
Assert.assertEquals(result, uncompressed);
}
Aggregations