List of usage examples for org.apache.hadoop.io.serializer Serialization getSerializer
Serializer<T> getSerializer(Class<T> c);
From source file:com.datasalt.pangool.tuplemr.SerializationInfo.java
License:Apache License
public static Serializer[] getSerializers(Schema schema, Configuration conf) { Serializer[] result = new Serializer[schema.getFields().size()]; for (int i = 0; i < result.length; i++) { Field field = schema.getField(i); if (field.getObjectSerialization() != null) { Serialization serialization = ReflectionUtils.newInstance(field.getObjectSerialization(), conf); if (serialization instanceof FieldConfigurable) { ((FieldConfigurable) serialization).setFieldProperties(field.getProps()); }/*from ww w . jav a 2s . c o m*/ result[i] = serialization.getSerializer(field.getObjectClass()); } } return result; }
From source file:cz.seznam.euphoria.hadoop.utils.Cloner.java
License:Apache License
/** * Help method retrieving a cloner for given class type from the * given configuration./* w ww . j av a 2 s.c o m*/ * * @param <T> the type of objects the resulting cloner will be able to handle * * @param what the class for which to retrieve a cloner * @param conf the hadoop configuration defining the serializer/deserializer * to utilize for cloning * * @return a cloner instance able to clone objects of the specified type */ static <T> Cloner<T> get(Class<T> what, Configuration conf) { SerializationFactory factory = new SerializationFactory(conf); Serialization<T> serialization = factory.getSerialization(what); if (serialization == null) { // FIXME: if we cannot (de)serialize just do not clone return t -> t; } Deserializer<T> deserializer = serialization.getDeserializer(what); Serializer<T> serializer = serialization.getSerializer(what); return (T elem) -> { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); serializer.open(baos); serializer.serialize(elem); serializer.close(); byte[] serialized = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(serialized); deserializer.open(bais); T deserialized = deserializer.deserialize(null); deserializer.close(); return deserialized; } catch (IOException ex) { throw new RuntimeException(ex); } }; }
From source file:org.apache.ignite.internal.processors.hadoop.impl.v2.HadoopSerializationWrapper.java
License:Apache License
/** * @param serialization External serializer to wrap. * @param cls The class to serialize./* ww w. ja v a 2 s. c o m*/ */ public HadoopSerializationWrapper(Serialization<T> serialization, Class<T> cls) throws IgniteCheckedException { assert cls != null; serializer = serialization.getSerializer(cls); deserializer = serialization.getDeserializer(cls); try { serializer.open(outStream); deserializer.open(inStream); } catch (IOException e) { throw new IgniteCheckedException(e); } }
From source file:org.apache.ignite.internal.processors.hadoop.v2.GridHadoopSerializationWrapper.java
License:Apache License
/** * @param serialization External serializer to wrap. * @param cls The class to serialize./*from w ww . j a va 2 s . c o m*/ */ public GridHadoopSerializationWrapper(Serialization<T> serialization, Class<T> cls) throws IgniteCheckedException { assert cls != null; serializer = serialization.getSerializer(cls); deserializer = serialization.getDeserializer(cls); try { serializer.open(outStream); deserializer.open(inStream); } catch (IOException e) { throw new IgniteCheckedException(e); } }
From source file:org.gridgain.grid.kernal.processors.hadoop.v2.GridHadoopSerializationWrapper.java
License:Open Source License
/** * @param serialization External serializer to wrap. * @param cls The class to serialize./*ww w.java 2 s . co m*/ */ public GridHadoopSerializationWrapper(Serialization<T> serialization, Class<T> cls) throws GridException { assert cls != null; serializer = serialization.getSerializer(cls); deserializer = serialization.getDeserializer(cls); try { serializer.open(outStream); deserializer.open(inStream); } catch (IOException e) { throw new GridException(e); } }