List of usage examples for org.apache.commons.lang3 SerializationUtils serialize
public static byte[] serialize(final Serializable obj)
Serializes an Object to a byte array for storage/serialization.
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); }//from ww w . jav a 2s . 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 a va 2 s .c o m*/ 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 a 2s . 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//from w w w. java 2 s . com 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()); }
From source file:org.jimsey.projects.turbine.fuel.camel.TurbineObjectConverter.java
@Converter public static byte[] toBytes(final Entity entity, final Exchange exchange) { return SerializationUtils.serialize(entity); }
From source file:org.lightjason.agentspeak.action.buildin.crypto.CEncrypt.java
@Override public final IFuzzyValue<Boolean> execute(final IContext p_context, final boolean p_parallel, final List<ITerm> p_argument, final List<ITerm> p_return, final List<ITerm> p_annotation) { final Key l_key = p_argument.get(0).raw(); final EAlgorithm l_algorithm = EAlgorithm.from(l_key.getAlgorithm()); return CFuzzyValue.from(p_argument.subList(1, p_argument.size()).stream() .map(i -> SerializationUtils.serialize(i.raw())).allMatch(i -> { try { p_return.add(CRawTerm.from(Base64.getEncoder() .encodeToString(l_algorithm.getEncryptCipher(l_key).doFinal(i)))); return true; } catch (final NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | BadPaddingException | IllegalBlockSizeException l_exception) { return false; }/*from w w w . j a v a 2s .c o m*/ })); }
From source file:org.lightjason.agentspeak.action.builtin.crypto.CEncrypt.java
/** * encrypts a datatset//from ww w . j a v a 2 s. c o m * * @param p_algorithm algorithm * @param p_key key * @param p_dataset dataset * @param p_return return argument * @return successful execution */ private static boolean encrypt(@Nonnull final EAlgorithm p_algorithm, @Nonnull final Key p_key, @Nonnull final Serializable p_dataset, @Nonnull final List<ITerm> p_return) { try { p_return.add(CRawTerm.from(Base64.getEncoder().encodeToString( p_algorithm.getEncryptCipher(p_key).doFinal(SerializationUtils.serialize(p_dataset))))); return true; } catch (final IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException l_exception) { return false; } }
From source file:org.lightjason.agentspeak.action.builtin.crypto.CHash.java
/** * serialize data/*from ww w . j av a 2s . c o m*/ * * @param p_context execution context * @param p_object term object * @return serialized bytes * * @note strings will be serialized always with utf-8 encoding, so comparing with md5sum is possible */ private static byte[] serialize(@Nonnull final IContext p_context, @Nonnull final ITerm p_object) { try { return CCommon.rawvalueAssignableTo(p_object, String.class) ? p_object.<String>raw().getBytes("UTF-8") : SerializationUtils.serialize(p_object.<Serializable>raw()); } catch (final UnsupportedEncodingException l_exception) { throw new CRuntimeException(l_exception, p_context); } }
From source file:org.nickelproject.nickel.objectStore.Util.java
public static byte[] bytesFromObject(final Serializable object) { return SerializationUtils.serialize(object); }