use of org.apache.avro.specific.SpecificFixed in project gora by apache.
the class SpecificFixedSerializer method fromByteBuffer.
@Override
public SpecificFixed fromByteBuffer(ByteBuffer byteBuffer) {
if (byteBuffer == null) {
return null;
}
Object value = null;
try {
value = clazz.newInstance();
} catch (InstantiationException ie) {
LOG.warn("Instantiation error for class=" + clazz, ie);
return null;
} catch (IllegalAccessException iae) {
LOG.warn("Illegal access error for class=" + clazz, iae);
return null;
}
if (!(value instanceof SpecificFixed)) {
LOG.warn("Not an instance of SpecificFixed");
return null;
}
SpecificFixed fixed = (SpecificFixed) value;
byte[] bytes = fixed.bytes();
try {
byteBuffer.get(bytes, 0, bytes.length);
} catch (BufferUnderflowException e) {
// LOG.info(e.toString() + " : class=" + clazz.getName() + " length=" + bytes.length);
throw e;
}
fixed.bytes(bytes);
return fixed;
}
use of org.apache.avro.specific.SpecificFixed in project gora by apache.
the class GoraSerializerTypeInferer method getSerializer.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> Serializer<T> getSerializer(Object value) {
Serializer serializer = null;
if (value == null) {
serializer = ByteBufferSerializer.get();
} else if (value instanceof CharSequence) {
serializer = CharSequenceSerializer.get();
} else if (value instanceof Utf8) {
serializer = CharSequenceSerializer.get();
} else if (value instanceof Boolean) {
serializer = BooleanSerializer.get();
} else if (value instanceof ByteBuffer) {
serializer = ByteBufferSerializer.get();
} else if (value instanceof byte[]) {
serializer = BytesArraySerializer.get();
} else if (value instanceof Double) {
serializer = DoubleSerializer.get();
} else if (value instanceof Float) {
serializer = FloatSerializer.get();
} else if (value instanceof Integer) {
serializer = IntegerSerializer.get();
} else if (value instanceof Long) {
serializer = LongSerializer.get();
} else if (value instanceof String) {
serializer = StringSerializer.get();
} else if (value instanceof SpecificFixed) {
serializer = SpecificFixedSerializer.get(value.getClass());
} else if (value instanceof GenericArray) {
Schema schema = ((GenericArray) value).getSchema();
if (schema.getType() == Type.ARRAY) {
schema = schema.getElementType();
}
serializer = ListSerializer.get(schema);
} else if (value instanceof Map) {
Map map = (Map) value;
if (map.size() == 0) {
serializer = ByteBufferSerializer.get();
} else {
Object value0 = map.values().iterator().next();
Schema schema = TypeUtils.getSchema(value0);
serializer = MapSerializer.get(schema);
}
} else if (value instanceof Persistent) {
serializer = ObjectSerializer.get();
} else {
serializer = SerializerTypeInferer.getSerializer(value);
}
return serializer;
}
Aggregations