Package org.apache.avro.util

Examples of org.apache.avro.util.Utf8


    GenericRecord valueRecord = new GenericData.Record(valueSchema);
    List<Schema.Field> fieldSchemas = valueSchema.getFields();
    for (int i = 0; i < val.getValues().size(); ++i) {
      Schema.Type type = fieldSchemas.get(i).schema().getType();
      if (type.equals(Schema.Type.STRING)) {
        Utf8 utf8 = new Utf8((String) val.getValues().get(i).toString());
        valueRecord.put(i, utf8);
      } else {
        valueRecord.put(i, val.getValues().get(i));
      }
    }
View Full Code Here


    GenericRecord valueRecord = new GenericData.Record(valueSchema);
    List<Schema.Field> fieldSchemas = valueSchema.getFields();
    for (int i = 0; i < val.getValues().size(); ++i) {
      Schema.Type type = fieldSchemas.get(i).schema().getType();
      if (type.equals(Schema.Type.STRING)) {
        Utf8 utf8 = new Utf8((String) val.getValues().get(i).toString());
        valueRecord.put(i, utf8);
      } else {
        valueRecord.put(i, val.getValues().get(i));
      }
    }
View Full Code Here

    GenericRecord valueRecord = new GenericData.Record(valueSchema);
    List<Schema.Field> fieldSchemas = valueSchema.getFields();
    for (int i = 0; i < val.getValues().size(); ++i) {
      Schema.Type type = fieldSchemas.get(i).schema().getType();
      if (type.equals(Schema.Type.STRING)) {
        Utf8 utf8 = new Utf8((String) val.getValues().get(i).toString());
        valueRecord.put(i, utf8);
      } else {
        valueRecord.put(i, val.getValues().get(i));
      }
    }
View Full Code Here

        String className = "java=org.apache.avro.ipc.HandshakeRequest";

        HandshakeRequest req = new HandshakeRequest();
        // set a few values to avoid NPEs
        req.clientHash = new MD5();
        req.clientProtocol = new Utf8("");
        req.serverHash = new MD5();

        AvroSpecificSerializer<HandshakeRequest> serializer = new AvroSpecificSerializer<HandshakeRequest>(className);
        byte[] bytes = serializer.toBytes(req);
        byte[] bytes2 = serializer.toBytes(req);
View Full Code Here

    }

    public void testRoundtripAvroWithString() throws Exception {
        String jsonSchema = "{\"name\": \"Str\", \"type\": \"string\"}";
        AvroGenericSerializer serializer = new AvroGenericSerializer(jsonSchema);
        byte[] bytes = serializer.toBytes(new Utf8("BAR"));
        byte[] bytes2 = serializer.toBytes(new Utf8("BAR"));
        assertEquals(ByteUtils.compare(bytes, bytes2), 0);
        assertTrue(serializer.toObject(bytes).equals(new Utf8("BAR")));
    }
View Full Code Here

                            + "]}";

        AvroGenericSerializer serializer = new AvroGenericSerializer(jsonSchema);
        Record record = new Record(Schema.parse(jsonSchema));
        // we need to use a Utf8 instance to map to a String.
        record.put("name", new Utf8("Hello"));
        byte[] bytes = serializer.toBytes(record);
        assertTrue(serializer.toObject(bytes).equals(record));
    }
View Full Code Here

public class AvroBackwardsCompatibilityTest {

    private static byte[] writeVersion0(Schema s0) {

        GenericData.Record record = new GenericData.Record(s0);
        record.put("original", new Utf8("Abhinay"));
        AvroVersionedGenericSerializer serializer = new AvroVersionedGenericSerializer(s0.toString());
        return serializer.toBytes(record);

    }
View Full Code Here

    }

    private static byte[] writeVersion0with1Present(Map<Integer, String> versions, Schema s0) {

        GenericData.Record record = new GenericData.Record(s0);
        record.put("original", new Utf8("Abhinay"));
        AvroVersionedGenericSerializer serializer = new AvroVersionedGenericSerializer(versions);
        return serializer.toBytes(record);

    }
View Full Code Here

    int count = randGenerator.getNextInt()%getMaxNumberOfMapFields();
    for(int i =0 ; i < count ; i++ )
    {
      SchemaFiller filler = SchemaFiller.createRandomField(fakeField); // create a new filler each time to emulate null-able fields
      map.put(new Utf8(field.name()+i), filler.generateRandomObject());
    }
    return map;
  }
View Full Code Here

  }

  @Override
  public Utf8 readString(Utf8 old) throws IOException {
    int length = readInt();
    Utf8 result = (old != null ? old : new Utf8());
    result.setByteLength(length);
    if (0 != length) {
      doReadBytes(result.getBytes(), 0, length);
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of org.apache.avro.util.Utf8

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.