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.util.MockCollector.java

@Override
public void collect(T record) {
    T copied = SerializationUtils.deserialize(SerializationUtils.serialize((Serializable) record));
    outputs.add(copied);
}

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

@Override
public void collect(StreamRecord<T> record) {
    T copied = SerializationUtils.deserialize(SerializationUtils.serialize((Serializable) record.getValue()));
    outputs.add(copied);
}

From source file:org.apache.flink.streaming.util.serialization.TypeSerializationTest.java

@SuppressWarnings("unchecked")
@Test//from  w  ww .  j av a 2 s  .c  o m
public void functionTypeSerializationTest() {
    TypeWrapper<Integer> ser = new FunctionTypeWrapper<Integer>(new MyMap(), RichMapFunction.class, 0);

    byte[] serializedType = SerializationUtils.serialize(ser);

    TypeWrapper<Integer> ser2 = (TypeWrapper<Integer>) SerializationUtils.deserialize(serializedType);

    assertNotNull(ser.getTypeInfo());
    assertNotNull(ser2.getTypeInfo());

    assertEquals(ser.getTypeInfo(), ser2.getTypeInfo());
}

From source file:org.apache.flink.streaming.util.serialization.TypeSerializationTest.java

@SuppressWarnings("unchecked")
@Test/*www .j  a  v a2  s  .  co  m*/
public void objectTypeSerializationTest() {
    Integer instance = Integer.valueOf(22);

    TypeWrapper<Integer> ser = new ObjectTypeWrapper<Integer>(instance);

    byte[] serializedType = SerializationUtils.serialize(ser);

    TypeWrapper<Integer> ser2 = (TypeWrapper<Integer>) SerializationUtils.deserialize(serializedType);

    assertNotNull(ser.getTypeInfo());
    assertNotNull(ser2.getTypeInfo());

    assertEquals(ser.getTypeInfo(), ser2.getTypeInfo());
}

From source file:org.apache.kylin.rest.response.SQLResponse.java

public void setCubeSegmentStatisticsList(
        List<QueryContext.CubeSegmentStatisticsResult> cubeSegmentStatisticsList) {
    try {//from  ww  w . ja  va  2  s . c o m
        this.queryStatistics = cubeSegmentStatisticsList == null ? null
                : SerializationUtils.serialize((Serializable) cubeSegmentStatisticsList);
    } catch (Exception e) { // serialize exception should not block query
        logger.warn("Error while serialize queryStatistics due to " + e);
        this.queryStatistics = null;
    }
}

From source file:org.apache.kylin.storage.hbase.ii.coprocessor.endpoint.EndpointTupleIterator.java

private IIProtos.IIRequest prepareRequest() throws IOException {
    IIProtos.IIRequest.Builder builder = IIProtos.IIRequest.newBuilder();

    if (this.tsRange != null) {
        byte[] tsRangeBytes = SerializationUtils.serialize(this.tsRange);
        builder.setTsRange(HBaseZeroCopyByteString.wrap(tsRangeBytes));
    }//from  w  w w  .  j av a  2s  .c  om

    builder.setType(HBaseZeroCopyByteString.wrap(CoprocessorRowType.serialize(pushedDownRowType))) //
            .setFilter(HBaseZeroCopyByteString.wrap(CoprocessorFilter.serialize(pushedDownFilter))) //
            .setProjector(HBaseZeroCopyByteString.wrap(CoprocessorProjector.serialize(pushedDownProjector))) //
            .setAggregator(HBaseZeroCopyByteString.wrap(EndpointAggregators.serialize(pushedDownAggregators)));

    IIProtos.IIRequest request = builder.build();

    return request;
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testLang303() throws ParseException {
    DateParser parser = getInstance(YMD_SLASH);
    final Calendar cal = Calendar.getInstance();
    cal.set(2004, Calendar.DECEMBER, 31);

    final Date date = parser.parse("2004/11/31");

    parser = SerializationUtils.deserialize(SerializationUtils.serialize((Serializable) parser));
    assertEquals(date, parser.parse("2004/11/31"));
}

From source file:org.apache.metamodel.csv.CsvTableTest.java

@Test
public void testSerializeAndDeserializeCurrentVersion() throws Exception {
    final DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
    final Table table1 = dc.getDefaultSchema().getTables().get(0);
    assertPeopleCsv(table1);//from   w  ww  .j a  va  2 s.c o m

    final byte[] bytes = SerializationUtils.serialize(table1);

    try (LegacyDeserializationObjectInputStream in = new LegacyDeserializationObjectInputStream(
            new ByteArrayInputStream(bytes))) {
        final Object object = in.readObject();

        assertPeopleCsv(object);
    }
}

From source file:org.apache.metron.stellar.common.utils.hashing.DefaultHasher.java

/**
 * {@inheritDoc}/*from  www  .jav  a2  s. c  om*/
 *
 * Returns a hash which has been encoded using the supplied encoder. If input is null then a string
 * containing all '0' will be returned. The length of the string is determined by the hashing algorithm
 * used.
 * @param toHash The value to hash.
 * @return A hash of {@code toHash} that has been encoded.
 * @throws EncoderException If unable to encode the hash then this exception occurs.
 * @throws NoSuchAlgorithmException If the supplied algorithm is not known.
 */
@Override
public String getHash(final Object toHash) throws EncoderException, NoSuchAlgorithmException {
    final MessageDigest messageDigest = MessageDigest.getInstance(algorithm);

    if (toHash == null) {
        return StringUtils.repeat("00", messageDigest.getDigestLength());
    } else if (toHash instanceof String) {
        return getHash(messageDigest, toHash.toString().getBytes(charset));
    } else if (toHash instanceof Serializable) {
        final byte[] serialized = SerializationUtils.serialize((Serializable) toHash);
        return getHash(messageDigest, serialized);
    }

    return null;
}

From source file:org.apache.openejb.activemq.JMS2AMQTest.java

@Test
public void serialize() throws SystemException, NotSupportedException, HeuristicRollbackException,
        HeuristicMixedException, RollbackException {
    final JMSContext c = SerializationUtils
            .deserialize(SerializationUtils.serialize(Serializable.class.cast(context)));
    ut.begin();//from   w  w w .  j  a va2s.  c o  m
    session.ok();
    ut.commit();
}