Example usage for org.apache.commons.lang3 SerializationUtils serialize

List of usage examples for org.apache.commons.lang3 SerializationUtils serialize

Introduction

In this page you can find the example usage for org.apache.commons.lang3 SerializationUtils serialize.

Prototype

public static byte[] serialize(final Serializable obj) 

Source Link

Document

Serializes an Object to a byte array for storage/serialization.

Usage

From source file:org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.java

/**
 * Ads a data source thus opening a {@link DataStream}.
 * // w ww  .j a  v  a 2 s . com
 * @param function
 *            the user defined function
 * @param <OUT>
 *            type of the returned stream
 * @return the data stream constructed
 */
public <OUT> DataStreamSource<OUT> addSource(SourceFunction<OUT> function) {
    TypeWrapper<OUT> outTypeWrapper = new FunctionTypeWrapper<OUT>(function, SourceFunction.class, 0);
    DataStreamSource<OUT> returnStream = new DataStreamSource<OUT>(this, "source", outTypeWrapper);

    try {
        jobGraphBuilder.addStreamVertex(returnStream.getId(), new SourceInvokable<OUT>(function), null,
                outTypeWrapper, "source", SerializationUtils.serialize(function), 1);
    } catch (SerializationException e) {
        throw new RuntimeException("Cannot serialize SourceFunction");
    }

    return returnStream;
}

From source file:org.apache.flink.streaming.api.StreamConfig.java

private void setTypeWrapper(String key, TypeWrapper<?> typeWrapper) {
    config.setBytes(key, SerializationUtils.serialize(typeWrapper));
}

From source file:org.apache.flink.streaming.api.StreamConfig.java

public void setUserInvokable(StreamInvokable<?, ?> invokableObject) {
    if (invokableObject != null) {
        config.setClass(USER_FUNCTION, invokableObject.getClass());

        try {/*from  w  ww . j a va  2 s.c  o  m*/
            config.setBytes(SERIALIZEDUDF, SerializationUtils.serialize(invokableObject));
        } catch (SerializationException e) {
            throw new RuntimeException("Cannot serialize invokable object " + invokableObject.getClass(), e);
        }
    }
}

From source file:org.apache.flink.streaming.api.StreamConfig.java

public <T> void setPartitioner(int outputIndex, StreamPartitioner<T> partitionerObject) {

    config.setBytes(PARTITIONER_OBJECT + outputIndex, SerializationUtils.serialize(partitionerObject));
}

From source file:org.apache.flink.streaming.api.StreamConfig.java

public void setOutputName(int outputIndex, List<String> outputName) {
    if (outputName != null) {
        config.setBytes(OUTPUT_NAME + outputIndex, SerializationUtils.serialize((Serializable) outputName));
    }/*from   ww w.  j  av  a  2s  . c  o  m*/
}

From source file:org.apache.flink.streaming.api.StreamConfig.java

public void setOperatorStates(Map<String, OperatorState<?>> states) {
    config.setBytes(OPERATOR_STATES, SerializationUtils.serialize((Serializable) states));
}

From source file:org.apache.flink.streaming.connectors.db.DefaultDBSerializer.java

@Override
public byte[] write(T object) {
    return SerializationUtils.serialize(object);
}

From source file:org.apache.flink.streaming.connectors.kafka.config.StringSerializer.java

public String serialize(T element) {
    byte[] serialized = SerializationUtils.serialize(element);
    return Base64.encodeBase64String(serialized);
}

From source file:org.apache.flink.streaming.connectors.util.JavaDefaultStringSchema.java

@Override
public byte[] serialize(String element) {
    return SerializationUtils.serialize(element);
}

From source file:org.apache.flink.streaming.util.CollectorOutput.java

@Override
public void collect(StreamRecord<T> record) {
    T copied = SerializationUtils.deserialize(SerializationUtils.serialize((Serializable) record.getValue()));
    list.add(record.copy(copied));//from w  w w . j a v  a  2  s . c o m
}