Search in sources :

Example 1 with ChunkedByteStringWriter

use of com.linkedin.data.ChunkedByteStringWriter 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 2 with ChunkedByteStringWriter

use of com.linkedin.data.ChunkedByteStringWriter in project rest.li by linkedin.

the class FeedDownloadResourceReactive method get.

@Override
public void get(Long key, @CallbackParam Callback<UnstructuredDataReactiveResult> callback) {
    ChunkedByteStringWriter writer = new ChunkedByteStringWriter(CONTENT, 2);
    callback.onSuccess(new UnstructuredDataReactiveResult(EntityStreams.newEntityStream(writer), CONTENT_TYPE));
}
Also used : UnstructuredDataReactiveResult(com.linkedin.restli.server.UnstructuredDataReactiveResult) ChunkedByteStringWriter(com.linkedin.data.ChunkedByteStringWriter)

Aggregations

ChunkedByteStringWriter (com.linkedin.data.ChunkedByteStringWriter)2 ByteString (com.linkedin.data.ByteString)1 ChunkedByteStringCollector (com.linkedin.data.ChunkedByteStringCollector)1 DataMap (com.linkedin.data.DataMap)1 CollectingReader (com.linkedin.entitystream.CollectingReader)1 UnstructuredDataReactiveResult (com.linkedin.restli.server.UnstructuredDataReactiveResult)1 Test (org.testng.annotations.Test)1