Package com.linkedin.data

Examples of com.linkedin.data.ByteString


                    buildPathKeys());

    methodDescriptor = model.findActionMethod("byteStringParam", ResourceLevel.COLLECTION);
    resource = getMockResource(CombinedResources.TestActionsResource.class);
    String str = "test string";
    ByteString expectedByteString = ByteString.copyString(str, "UTF-8");
    resource.byteStringParam(expectedByteString);
    EasyMock.expectLastCall().once();
    jsonEntityBody = RestLiTestHelper.doubleQuote("{'byteStringParam': '" + str + "'}");
    checkInvocation(resource,
                    methodDescriptor,
View Full Code Here


      for (int i = 0; i < size; i++)
      {
        sb.append((char) ('a' + i % 26));
      }
      String stringValue = sb.toString();
      ByteString byteStringValue = ByteString.copy(stringValue.getBytes(Data.UTF_8_CHARSET));

      // Object ctor, value is String
      T fixed = objectConstructor.newInstance(stringValue);
      assertEquals(fixed.data(), byteStringValue);
      assertSame(fixed.data(), fixed.bytes());

      // Object ctor, value is ByteString
      fixed = objectConstructor.newInstance(byteStringValue);
      assertSame(fixed.data(), byteStringValue);
      assertSame(fixed.data(), fixed.bytes());

      // ByteString ctor
      fixed = byteStringConstructor.newInstance(byteStringValue);
      assertSame(fixed.data(), byteStringValue);
      assertSame(fixed.data(), fixed.bytes());

      // schema()
      assertSame(fixed.schema(), schema);

      // toString()
      assertEquals(fixed.toString(), byteStringValue.toString());

      // check for clone and copy override with correct return type
      TestDataTemplateUtil.assertCloneAndCopyReturnType(fixedClass);

      // test clone
View Full Code Here

    for (Map.Entry<String, String> e : headers.entrySet())
    {
      // TODO multi-valued headers
      resp.setHeader(e.getKey(), e.getValue());
    }
    final ByteString entity = restResponse.getEntity();
    entity.write(resp.getOutputStream());

    resp.getOutputStream().close();
  }
View Full Code Here

                  uri.getPath(),
                  null,
                  uri.getFragment());

    // If there's no existing body, just pass the request as x-www-form-urlencoded
    ByteString entity = request.getEntity();
    if (entity == null || entity.length() == 0)
    {
      requestBuilder.setHeader(HEADER_CONTENT_TYPE, FORM_URL_ENCODED);
      requestBuilder.setEntity(ByteString.copyString(query, Data.UTF_8_CHARSET));
    }
    else
View Full Code Here

  public Response<T> decodeResponse(RestResponse restResponse) throws RestLiDecodingException
  {
    ResponseImpl<T> response = new ResponseImpl<T>(restResponse.getStatus(), restResponse.getHeaders());

    ByteString entity = restResponse.builder().getEntity();

    try
    {
      DataMap dataMap;
      if (entity.length() == 0)
      {
        dataMap = null;
      }
      else
      {
        InputStream inputStream = entity.asInputStream();
        if ((RestConstants.HEADER_VALUE_APPLICATION_PSON)
                .equalsIgnoreCase(restResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE)))
        {
          dataMap = PSON_DATA_CODEC.readMap(inputStream);
        }
View Full Code Here

    }

    final byte[] eb = out.toByteArray();
    // Strip off the last CRLF. We added this in writeEntity for convenience when working with
    // other tools.
    final ByteString entity;
    if (eb.length >= 2 && eb[eb.length-2] == CR_CHAR && eb[eb.length-1] == LF_CHAR)
    {
      entity = ByteString.copyString(new String(eb, 0, eb.length - 2), CHARSET);
    }
    else
View Full Code Here

    public ByteString coerceOutput(Object object) throws TemplateOutputCastException
    {
      if (object.getClass() == String.class)
      {
        String input = (String) object;
        ByteString bytes = ByteString.copyAvroString(input, true);
        if (bytes == null)
        {
          throw new TemplateOutputCastException("Output " + object + " is not a valid string encoding of bytes");
        }
        return bytes;
View Full Code Here

    RestRequest request = rb.build();
    Future<RestResponse> f = client.restRequest(request);

    // This will block
    RestResponse response = f.get();
    final ByteString entity = response.getEntity();
    if (entity != null) {
      System.out.println(entity.asString("UTF-8"));
    } else {
      System.out.println("NOTHING!");
    }

    assertEquals(response.getStatus(), 200);
View Full Code Here

        throw new TemplateOutputCastException("String is not a valid representation of bytes");
      }
    }
    else if (objectClass == ByteString.class)
    {
      ByteString bytes = (ByteString) object;
      if (bytes.length() != schema.getSize())
      {
        throw new TemplateOutputCastException("Fixed size is " + schema.getSize() + ", ByteString length is " + bytes.length());
      }
      _schema = schema;
      _data = bytes;
    }
    else
View Full Code Here

TOP

Related Classes of com.linkedin.data.ByteString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.