Search in sources :

Example 1 with ChunkedByteStringCollector

use of com.linkedin.data.ChunkedByteStringCollector 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;
}
Also used : DataList(com.linkedin.data.DataList) ByteString(com.linkedin.data.ByteString) ChunkedByteStringCollector(com.linkedin.data.ChunkedByteStringCollector) CollectingReader(com.linkedin.entitystream.CollectingReader) DataMap(com.linkedin.data.DataMap)

Example 2 with ChunkedByteStringCollector

use of com.linkedin.data.ChunkedByteStringCollector 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);
}
Also used : ByteString(com.linkedin.data.ByteString) ChunkedByteStringCollector(com.linkedin.data.ChunkedByteStringCollector) ChunkedByteStringWriter(com.linkedin.data.ChunkedByteStringWriter) ByteString(com.linkedin.data.ByteString) CollectingReader(com.linkedin.entitystream.CollectingReader) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 3 with ChunkedByteStringCollector

use of com.linkedin.data.ChunkedByteStringCollector 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;
}
Also used : DataList(com.linkedin.data.DataList) ByteString(com.linkedin.data.ByteString) ChunkedByteStringCollector(com.linkedin.data.ChunkedByteStringCollector) CollectingReader(com.linkedin.entitystream.CollectingReader) DataMap(com.linkedin.data.DataMap)

Example 4 with ChunkedByteStringCollector

use of com.linkedin.data.ChunkedByteStringCollector 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;
}
Also used : DataList(com.linkedin.data.DataList) ByteString(com.linkedin.data.ByteString) ChunkedByteStringCollector(com.linkedin.data.ChunkedByteStringCollector) CollectingReader(com.linkedin.entitystream.CollectingReader) DataMap(com.linkedin.data.DataMap)

Example 5 with ChunkedByteStringCollector

use of com.linkedin.data.ChunkedByteStringCollector 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;
}
Also used : DataList(com.linkedin.data.DataList) ByteString(com.linkedin.data.ByteString) ChunkedByteStringCollector(com.linkedin.data.ChunkedByteStringCollector) CollectingReader(com.linkedin.entitystream.CollectingReader) DataMap(com.linkedin.data.DataMap)

Aggregations

ByteString (com.linkedin.data.ByteString)5 ChunkedByteStringCollector (com.linkedin.data.ChunkedByteStringCollector)5 DataMap (com.linkedin.data.DataMap)5 CollectingReader (com.linkedin.entitystream.CollectingReader)5 DataList (com.linkedin.data.DataList)4 ChunkedByteStringWriter (com.linkedin.data.ChunkedByteStringWriter)1 Test (org.testng.annotations.Test)1