Package com.linkedin.data

Examples of com.linkedin.data.ByteString


        }
        else
        {
          if (_options.getCoercionMode() != CoercionMode.OFF)
          {
            ByteString bytes = ByteString.copyAvroString(str, true);
            if (bytes != null)
            {
              _hasFix = true;
              fixed = bytes;
            }
            else
            {
              error = true;
            }
          }
          else
          {
            error = ! Data.validStringAsBytes(str);
          }
        }
        if (error)
        {
          addMessage(element, "\"%1$s\" is not a valid string representation of bytes", str);
        }
      }
      else if (clazz == ByteString.class)
      {
        ByteString bytes = (ByteString) object;
        if (bytes.length() != size)
        {
          addMessage(element, "\"%1$s\" length (%2$d) is inconsistent with expected fixed size of %3$d", bytes, bytes.length(), size);
        }
      }
      else
      {
        addMessage(element, "fixed type is not backed by a String or ByteString");
View Full Code Here


      {
        String str = (String) object;
        boolean error = false;
        if (_options.getCoercionMode() != CoercionMode.OFF)
        {
          ByteString bytes = ByteString.copyAvroString(str, true);
          if (bytes != null)
          {
            _hasFix = true;
            fixed = bytes;
          }
View Full Code Here

      for (Map.Entry<String, String> e : response.getHeaders().entrySet())
      {
        nettyResponse.setHeader(e.getKey(), e.getValue());
      }
      final ByteString entity = response.getEntity();
      ChannelBuffer buf = ChannelBuffers.wrappedBuffer(entity.asByteBuffer());
      nettyResponse.setContent(buf);
      nettyResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, entity.length());

      return nettyResponse;
    }
View Full Code Here

          }
          result = value;
          break;
        case FIXED:
          clazz = value.getClass();
          ByteString byteString;
          if (clazz == String.class)
          {
            byteString = ByteString.copyAvroString((String) value, true);
          }
          else if (clazz == ByteString.class)
          {
            byteString = (ByteString) value;
          }
          else
          {
            throw new IllegalArgumentException(message(path, "fixed value %1$s is not a String or ByteString", value));
          }
          FixedDataSchema fixedDataSchema = (FixedDataSchema) dataSchema;
          if (fixedDataSchema.getSize() != byteString.length())
          {
            throw new IllegalArgumentException(message(path,
                                                       "ByteString size %1$d != FixedDataSchema size %2$d",
                                                       byteString.length(),
                                                       fixedDataSchema.getSize()));
          }
          result = byteString;
          break;
        case MAP:
View Full Code Here

    Assert.assertEquals(5.67F, foo.getFloat());
    foo.setDouble(4.45);
    Assert.assertEquals(4.45, foo.getDouble());
    foo.setLong(12345L);
    Assert.assertEquals(12345L, foo.getLong());
    ByteString byteString = ByteString.copyAvroString("someString", false);
    foo.setBytes(byteString);
    Assert.assertEquals(byteString, foo.getBytes());
    foo.setString("myString");
    Assert.assertEquals("myString", foo.getString());
    foo.setEnum(TestRecordAndUnionTemplate.EnumType.BANANA);
View Full Code Here

    List<?> castFrom = TestUtil.asList("88");
    List<?> castTo = TestUtil.asList(ByteString.copyAvroString("88", false));
    for (int i = 0; i < castFrom.size(); ++i)
    {
      map.put("bytes", castFrom.get(i));
      ByteString result = foo.getBytes();
      assertEquals(result, castTo.get(i));
    }

    // legacy test
    ByteString[] t = {
View Full Code Here

    List<?> castFrom = TestUtil.asList("8888");
    List<?> castTo = TestUtil.asList(ByteString.copyAvroString("8888", false));
    for (int i = 0; i < castFrom.size(); ++i)
    {
      map.put("fixed", castFrom.get(i));
      ByteString result = foo.getFixed().bytes();
      assertEquals(result, castTo.get(i));
    }
  }
View Full Code Here

        case STRING:
          result = value.toString();
          break;
        case BYTES:
          ByteBuffer byteBuffer = (ByteBuffer) value;
          ByteString byteString = ByteString.copy(byteBuffer);
          byteBuffer.rewind();
          result = byteString;
          break;
        case ENUM:
          String enumValue = value.toString();
View Full Code Here

    String goodObjects[] = {
        "12345",
        "ABCDF"
    };

    ByteString goodByteStrings[] = {
        ByteString.copyAvroString("qwert", false)
    };

    Object badObjects[] = {
        "", "1", "12", "123", "1234", "1234\u0100", "123456",
        1, 2.0f, 3.0, 4L, new DataMap(), new DataList()
    };

    ByteString badByteStrings[]  = {
        ByteString.copyAvroString("", false),
        ByteString.copyAvroString("a", false),
        ByteString.copyAvroString("ab", false),
        ByteString.copyAvroString("abc", false),
        ByteString.copyAvroString("abcd", false),
        ByteString.copyAvroString("abcdef", false)
    };

    Integer lastHashCode = null;
    ByteString lastByteString = null;
    for (String o : goodObjects)
    {
      Exception exc = null;
      Fixed5 fixed = null;
      try
      {
        fixed = new Fixed5(o);
      }
      catch (Exception e)
      {
        exc = e;
      }
      assertNull(exc);

      // equals
      ByteString expectedByteString = ByteString.copyAvroString(o, false);
      assertEquals(fixed.data(), expectedByteString);
      assertTrue(fixed.equals(new Fixed5(expectedByteString)));
      if (lastByteString != null)
      {
        assertFalse(fixed.equals(lastByteString));
      }
      assertFalse(fixed.equals(null));
      assertFalse(fixed.equals(new Object()));

      // hashCode
      int newHashCode = fixed.hashCode();
      if (lastHashCode != null)
      {
        assertTrue(newHashCode != lastHashCode);
      }

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

      lastHashCode = newHashCode;
      lastByteString = expectedByteString;

      // clone and copy
View Full Code Here

  public void testWrapping()
      throws InstantiationException, IllegalAccessException
  {
    String input = "12345";

    ByteString input1 = ByteString.copyAvroString(input, false);
    Fixed5 fixed1 = DataTemplateUtil.wrap(input1, Fixed5.class);
    assertSame(input1, fixed1.data());

    ByteString input2 = ByteString.copyAvroString("67890", false);
    Fixed5 fixed2 = DataTemplateUtil.wrap(input2, Fixed5.SCHEMA, Fixed5.class);
    assertSame(input2, fixed2.data());

    Fixed5 fixed3 =  DataTemplateUtil.wrap(input, Fixed5.class);
    assertEquals(fixed1, fixed3);
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.