Search in sources :

Example 11 with ByteString

use of com.linkedin.data.ByteString 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 12 with ByteString

use of com.linkedin.data.ByteString 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 13 with ByteString

use of com.linkedin.data.ByteString 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 14 with ByteString

use of com.linkedin.data.ByteString 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 15 with ByteString

use of com.linkedin.data.ByteString 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)152 Test (org.testng.annotations.Test)77 ByteArrayOutputStream (java.io.ByteArrayOutputStream)33 MimeMultipart (javax.mail.internet.MimeMultipart)31 MimeBodyPart (javax.mail.internet.MimeBodyPart)26 DataMap (com.linkedin.data.DataMap)25 RestResponse (com.linkedin.r2.message.rest.RestResponse)25 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)22 FullEntityReader (com.linkedin.r2.message.stream.entitystream.FullEntityReader)22 RestRequest (com.linkedin.r2.message.rest.RestRequest)21 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)21 URI (java.net.URI)21 CountDownLatch (java.util.concurrent.CountDownLatch)20 RequestContext (com.linkedin.r2.message.RequestContext)18 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)18 Callback (com.linkedin.common.callback.Callback)17 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)14 RestException (com.linkedin.r2.message.rest.RestException)12 HashMap (java.util.HashMap)12 DataList (com.linkedin.data.DataList)11