use of com.linkedin.entitystream.CollectingReader in project rest.li by linkedin.
the class TestJacksonJsonDataEncoder method encode.
private byte[] encode(DataComplex data) throws Exception {
JacksonJsonDataEncoder encoder = data instanceof DataMap ? new JacksonJsonDataEncoder((DataMap) data, 3) : new JacksonJsonDataEncoder((DataList) data, 3);
EntityStream<ByteString> entityStream = EntityStreams.newEntityStream(encoder);
CollectingReader<ByteString, ?, ChunkedByteStringCollector.Result> reader = new CollectingReader<>(new ChunkedByteStringCollector());
entityStream.setReader(reader);
return reader.getResult().toCompletableFuture().get().data;
}
use of com.linkedin.entitystream.CollectingReader in project rest.li by linkedin.
the class TestJacksonJsonDataEncoder method testStringInternDisabledByDefault.
/**
* Test to make sure that field names are not interned by default.
*/
@Test
public void testStringInternDisabledByDefault() throws Exception {
final String keyName = "testKey";
DataMap dataMap = new DataMap();
dataMap.put(keyName, 1);
JacksonJsonDataEncoder encoder = new JacksonJsonDataEncoder(dataMap, 3);
// make sure intern field names is disabled by default
assertFalse(encoder._jsonFactory.isEnabled(JsonFactory.Feature.INTERN_FIELD_NAMES));
EntityStream<ByteString> entityStream = EntityStreams.newEntityStream(encoder);
CollectingReader<ByteString, ?, ChunkedByteStringCollector.Result> reader = new CollectingReader<>(new ChunkedByteStringCollector());
entityStream.setReader(reader);
byte[] encoded = reader.getResult().toCompletableFuture().get().data;
JacksonJsonDataMapDecoder decoder = new JacksonJsonDataMapDecoder();
// make sure intern field names is disabled
assertFalse(decoder._jsonFactory.isEnabled(JsonFactory.Feature.INTERN_FIELD_NAMES));
Writer<ByteString> writer = new ChunkedByteStringWriter(encoded, 3);
entityStream = EntityStreams.newEntityStream(writer);
entityStream.setReader(decoder);
DataMap map = decoder.getResult().toCompletableFuture().get();
final String key = map.keySet().iterator().next();
assertEquals(key, keyName);
assertNotSame(key, keyName);
}
use of com.linkedin.entitystream.CollectingReader in project rest.li by linkedin.
the class TestJacksonLICORDataEncoder method actualEncode.
private byte[] actualEncode(DataComplex data, boolean encodeBinary) throws Exception {
JacksonLICORDataEncoder encoder = data instanceof DataMap ? new JacksonLICORDataEncoder((DataMap) data, 3, encodeBinary) : new JacksonLICORDataEncoder((DataList) data, 3, encodeBinary);
EntityStream<ByteString> entityStream = EntityStreams.newEntityStream(encoder);
CollectingReader<ByteString, ?, ChunkedByteStringCollector.Result> reader = new CollectingReader<>(new ChunkedByteStringCollector());
entityStream.setReader(reader);
return reader.getResult().toCompletableFuture().get().data;
}
use of com.linkedin.entitystream.CollectingReader in project rest.li by linkedin.
the class TestProtobufDataEncoder method actualEncode.
private byte[] actualEncode(DataComplex data) throws Exception {
ProtobufDataEncoder encoder = data instanceof DataMap ? new ProtobufDataEncoder((DataMap) data, 3) : new ProtobufDataEncoder((DataList) data, 3);
EntityStream<ByteString> entityStream = EntityStreams.newEntityStream(encoder);
CollectingReader<ByteString, ?, ChunkedByteStringCollector.Result> reader = new CollectingReader<>(new ChunkedByteStringCollector());
entityStream.setReader(reader);
return reader.getResult().toCompletableFuture().get().data;
}
use of com.linkedin.entitystream.CollectingReader in project rest.li by linkedin.
the class TestSmileDataEncoder method actualEncode.
private byte[] actualEncode(DataComplex data) throws Exception {
JacksonSmileDataEncoder encoder = data instanceof DataMap ? new JacksonSmileDataEncoder(SMILE_FACTORY, (DataMap) data, 3) : new JacksonSmileDataEncoder(SMILE_FACTORY, (DataList) data, 3);
EntityStream<ByteString> entityStream = EntityStreams.newEntityStream(encoder);
CollectingReader<ByteString, ?, ChunkedByteStringCollector.Result> reader = new CollectingReader<>(new ChunkedByteStringCollector());
entityStream.setReader(reader);
return reader.getResult().toCompletableFuture().get().data;
}
Aggregations