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

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

Introduction

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

Prototype

public static <T> T deserialize(final byte[] objectData) 

Source Link

Document

Deserializes a single Object from an array of bytes.

Usage

From source file:org.janusgraph.graphdb.database.serialize.attribute.SerializableSerializer.java

@Override
public T read(ScanBuffer buffer) {
    byte[] data = serializer.readObjectNotNull(buffer, byte[].class);
    return (T) SerializationUtils.deserialize(data);
}

From source file:org.jasig.cas.services.AttributeReleasePolicyTests.java

@Test
public void verifyAttributeFilterMappedAttributes() {
    final ReturnMappedAttributeReleasePolicy policy = new ReturnMappedAttributeReleasePolicy();
    final Map<String, String> mappedAttr = new HashMap<>();
    mappedAttr.put("attr1", "newAttr1");

    policy.setAllowedAttributes(mappedAttr);

    final Principal p = mock(Principal.class);

    final Map<String, Object> map = new HashMap<>();
    map.put("attr1", "value1");
    map.put("attr2", "value2");
    map.put("attr3", Arrays.asList("v3", "v4"));

    when(p.getAttributes()).thenReturn(map);
    when(p.getId()).thenReturn("principalId");

    final Map<String, Object> attr = policy.getAttributes(p);
    assertEquals(attr.size(), 1);//from   www  .j  av  a2 s  . c om
    assertTrue(attr.containsKey("newAttr1"));

    final byte[] data = SerializationUtils.serialize(policy);
    final ReturnMappedAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
    assertNotNull(p2);
    assertEquals(p2.getAllowedAttributes(), policy.getAllowedAttributes());
}

From source file:org.jasig.cas.services.AttributeReleasePolicyTests.java

@Test
public void verifyServiceAttributeFilterAllowedAttributes() {
    final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
    policy.setAllowedAttributes(Arrays.asList("attr1", "attr3"));
    final Principal p = mock(Principal.class);

    final Map<String, Object> map = new HashMap<>();
    map.put("attr1", "value1");
    map.put("attr2", "value2");
    map.put("attr3", Arrays.asList("v3", "v4"));

    when(p.getAttributes()).thenReturn(map);
    when(p.getId()).thenReturn("principalId");

    final Map<String, Object> attr = policy.getAttributes(p);
    assertEquals(attr.size(), 2);//w ww. j a  va 2s  .  com
    assertTrue(attr.containsKey("attr1"));
    assertTrue(attr.containsKey("attr3"));

    final byte[] data = SerializationUtils.serialize(policy);
    final ReturnAllowedAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
    assertNotNull(p2);
    assertEquals(p2.getAllowedAttributes(), policy.getAllowedAttributes());
}

From source file:org.jasig.cas.services.AttributeReleasePolicyTests.java

@Test
public void verifyServiceAttributeFilterAllowedAttributesWithARegexFilter() {
    final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
    policy.setAllowedAttributes(Arrays.asList("attr1", "attr3", "another"));
    policy.setAttributeFilter(new RegisteredServiceRegexAttributeFilter("v3"));
    final Principal p = mock(Principal.class);

    final Map<String, Object> map = new HashMap<>();
    map.put("attr1", "value1");
    map.put("attr2", "value2");
    map.put("attr3", Arrays.asList("v3", "v4"));

    when(p.getAttributes()).thenReturn(map);
    when(p.getId()).thenReturn("principalId");

    final Map<String, Object> attr = policy.getAttributes(p);
    assertEquals(attr.size(), 1);/*w  ww .  ja  va  2 s .  c om*/
    assertTrue(attr.containsKey("attr3"));

    final byte[] data = SerializationUtils.serialize(policy);
    final ReturnAllowedAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
    assertNotNull(p2);
    assertEquals(p2.getAllowedAttributes(), policy.getAllowedAttributes());
    assertEquals(p2.getAttributeFilter(), policy.getAttributeFilter());
}

From source file:org.jasig.cas.services.AttributeReleasePolicyTests.java

@Test
public void verifyServiceAttributeFilterAllAttributes() {
    final ReturnAllAttributeReleasePolicy policy = new ReturnAllAttributeReleasePolicy();
    final Principal p = mock(Principal.class);

    final Map<String, Object> map = new HashMap<>();
    map.put("attr1", "value1");
    map.put("attr2", "value2");
    map.put("attr3", Arrays.asList("v3", "v4"));

    when(p.getAttributes()).thenReturn(map);
    when(p.getId()).thenReturn("principalId");

    final Map<String, Object> attr = policy.getAttributes(p);
    assertEquals(attr.size(), map.size());

    final byte[] data = SerializationUtils.serialize(policy);
    final ReturnAllAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
    assertNotNull(p2);/*from w w  w .j  a  va 2 s  . c o  m*/
}

From source file:org.jasig.cas.services.support.RegisteredServiceRegexAttributeFilterTests.java

@Test
public void verifySerialization() {
    final byte[] data = SerializationUtils.serialize(this.filter);
    final AttributeFilter secondFilter = SerializationUtils.deserialize(data);
    assertEquals(secondFilter, this.filter);
}

From source file:org.javatuples.Test.java

public void testMain() throws Exception {

    final Decade<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> decade = Decade
            .with(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4),
                    Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8),
                    Integer.valueOf(9), Integer.valueOf(10));

    List<Integer> decadeList = new ArrayList<Integer>();

    for (final Object value : decade) {
        decadeList.add((Integer) value);
        System.out.println(value);
    }// w w w .  j  a va2s  .  c o  m

    final Decade<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> decade2 = Decade
            .fromCollection(decadeList);

    assertEquals(decade, decade2);

    final Decade<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> decade3 = Decade
            .fromIterable(decadeList);

    assertEquals(decade, decade3);

    final Decade<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> decade4 = Decade
            .fromIterable(decadeList, 0);

    assertEquals(decade, decade4);

    decadeList.add(Integer.valueOf(100));

    final Decade<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> decade5 = Decade
            .fromIterable(decadeList, 0);

    assertEquals(decade, decade5);

    final Decade<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> decade100 = Decade
            .with(Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5),
                    Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8), Integer.valueOf(9),
                    Integer.valueOf(10), Integer.valueOf(100));

    final Decade<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> decade6 = Decade
            .fromIterable(decadeList, 1);

    assertEquals(decade100, decade6);

    final Ennead<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> ennead = Ennead
            .with(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4),
                    Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8),
                    Integer.valueOf(9));

    System.out.println(ennead.addAt1("Pepito"));
    System.out.println(ennead.add(new Socket()));

    final Sextet<String, Integer, String, String, String, String> sextet = Sextet.with("1.0",
            Integer.valueOf(2), "3.0", "4.0", "5.0", "6.0");

    System.out.println(sextet);
    System.out.println(sextet.addAt3("Perico"));

    Pair<String, Object> pair = Pair.with("a", null);

    final Object o = null;
    assertTrue(pair.contains("a"));
    assertTrue(pair.contains(null));
    assertTrue(pair.containsAll(o));
    assertTrue(pair.containsAll(null, "a"));
    assertTrue(!pair.containsAll(null, "b"));

    final byte[] serSextet = SerializationUtils.serialize(sextet);
    System.out.println(Arrays.asList(ArrayUtils.toObject(serSextet)));
    final Sextet<String, Integer, String, String, String, String> sextetUnSer = (Sextet<String, Integer, String, String, String, String>) SerializationUtils
            .deserialize(serSextet);
    System.out.println(sextetUnSer);

    String str = null;
    Integer integ = null;
    Double[] doubleArray = null;

    Triplet<String, Integer, Double[]> triplet = Triplet.with(str, integ, doubleArray);

    System.out.println(triplet);

    Pair<String, Integer> pair1 = Pair.with("hello", Integer.valueOf(23));
    Quintet<String, Integer, Double, String, String> quintet = Quintet.with("a", Integer.valueOf(3),
            Double.valueOf(34.2), "b", "c");

    Pair<String, Integer> pair2 = new Pair<String, Integer>("hello", Integer.valueOf(23));
    Quintet<String, Integer, Double, String, String> quintet2 = new Quintet<String, Integer, Double, String, String>(
            "a", Integer.valueOf(3), Double.valueOf(34.2), "b", "c");

    System.out.println(pair1);
    System.out.println(pair2);
    System.out.println(quintet);
    System.out.println(quintet2);

    try {
        quintet2.getValue(8);
        assertTrue(false);
    } catch (IllegalArgumentException e) {
        // OK
    } catch (Exception e) {
        throw e;
    }

    final List<Tuple> tuples = new ArrayList<Tuple>();
    tuples.add(Quintet.with(0, 87, 21, 2, 2));
    tuples.add(Quintet.with(0, 1, 1, 4, 1));
    tuples.add(Quintet.with(0, 1, 1, 4, 0));
    tuples.add(Quintet.with(0, 1, 1, 4, 2));
    tuples.add(Quintet.with(24, 12, 99, 0, 14));
    tuples.add(Quintet.with(24, 12, 84, 4, 2));
    tuples.add(Quartet.with(24, 12, 84, 4));
    tuples.add(Quartet.with(24, 12, 84, 3));
    tuples.add(Quartet.with(24, 12, 84, 0));
    tuples.add(Quartet.with(25, 2, 84, 0));
    tuples.add(Quartet.with(22, 12, 84, 9));
    tuples.add(Sextet.with(0, 0, 0, 0, 0, 0));
    tuples.add(Sextet.with(0, 0, 0, 2, 0, 0));
    tuples.add(Sextet.with(0, 87, 21, 2, 1, 0));

    System.out.println("-");
    for (final Tuple tuple : tuples) {
        System.out.println(tuple);
    }
    Collections.sort(tuples);
    System.out.println("-");
    for (final Tuple tuple : tuples) {
        System.out.println(tuple);
    }
    System.out.println("-");

}

From source file:org.jimsey.project.turbine.spring.domain.IndicatorJsonTest.java

@Ignore
@Test/*from w  w  w.  j av  a  2s  . c om*/
public void testSerializable() throws IOException {
    indicator = new IndicatorJson(OffsetDateTime.now(), 100.0d, indicators, TurbineTestConstants.SYMBOL,
            TurbineTestConstants.MARKET, name, OffsetDateTime.now().toString());
    byte[] bytes = SerializationUtils.serialize(indicator);
    TickJson stock2 = (TickJson) SerializationUtils.deserialize(bytes);
    logger.info(indicator.toString());
    logger.info(stock2.toString());
}

From source file:org.jimsey.project.turbine.spring.domain.StrategyJsonTest.java

@Ignore
@Test// w w  w . ja v  a2 s .c  o m
public void testSerializable() throws IOException {
    strategy = new StrategyJson(1401174943825l, TurbineTestConstants.SYMBOL, TurbineTestConstants.MARKET,
            100.0d, "enter", "myname", 1, 6, 11.0d, 14.0d, OffsetDateTime.now().toString());
    byte[] bytes = SerializationUtils.serialize(strategy);
    TickJson strategy2 = (TickJson) SerializationUtils.deserialize(bytes);
    logger.info(strategy.toString());
    logger.info(strategy2.toString());
}

From source file:org.jimsey.project.turbine.spring.domain.TickJsonTest.java

@Ignore
@Test// w ww .j  a va 2s. c  o  m
public void testSerializable() throws IOException {
    tick = new TickJson(OffsetDateTime.now(), 99.52d, 99.58d, 98.99d, 99.08d, 100.0d,
            TurbineTestConstants.MARKET, TurbineTestConstants.SYMBOL, OffsetDateTime.now().toString());
    byte[] bytes = SerializationUtils.serialize(tick);
    TickJson tick2 = (TickJson) SerializationUtils.deserialize(bytes);
    logger.info(tick.toString());
    logger.info(tick2.toString());
}