Ejemplo n.º 1
0
 @SuppressWarnings("unchecked")
 private Record decodeRecord(
     final GenericRecord generic, @Nullable final Set<URI> propertiesToDecode) {
   final Record record = Record.create();
   final GenericRecord encodedID = (GenericRecord) generic.get(0);
   if (encodedID != null) {
     record.setID((URI) decodeIdentifier(encodedID));
   }
   for (final GenericRecord prop : (Iterable<GenericRecord>) generic.get(1)) {
     final URI property = (URI) decodeIdentifier((GenericRecord) prop.get(0));
     final List<Object> values = decodeNodes(prop.get(1));
     if (propertiesToDecode == null || propertiesToDecode.contains(property)) {
       record.set(property, values);
     }
   }
   return record;
 }
Ejemplo n.º 2
0
 private Object encodeRecord(final Record record, @Nullable final Set<URI> propertiesToEncode) {
   final URI id = record.getID();
   final Object encodedID = id == null ? null : encodeIdentifier(id);
   final List<Object> props = Lists.newArrayList();
   for (final URI property : record.getProperties()) {
     if (propertiesToEncode == null || propertiesToEncode.contains(property)) {
       ensureInDictionary(property);
       final List<? extends Object> nodes = record.get(property);
       if (property.equals(RDF.TYPE)) {
         for (final Object value : nodes) {
           if (value instanceof URI) {
             ensureInDictionary((URI) value);
           }
         }
       }
       final GenericData.Record prop = new GenericData.Record(Schemas.PROPERTY);
       prop.put("propertyURI", encodeIdentifier(property));
       prop.put("propertyValue", encodeNodes(nodes));
       props.add(prop);
     }
   }
   return SerializerAvro.newGenericRecord(Schemas.RECORD, encodedID, props);
 }