List of usage examples for org.apache.commons.lang SerializationUtils deserialize
public static Object deserialize(byte[] objectData)
Deserializes a single Object
from an array of bytes.
From source file:org.archive.url.UsableURIFactoryTest.java
/** * A UURI's string representation should be same after a * serialization roundtrip. //w w w .j a v a 2 s . c o m * * @throws URIException */ public final void testSerializationRoundtrip() throws URIException { UsableURI uuri = UsableURIFactory.getInstance("http://www.example.com/path?query#anchor"); UsableURI uuri2 = (UsableURI) SerializationUtils.deserialize(SerializationUtils.serialize(uuri)); assertEquals("Not equal", uuri.toString(), uuri2.toString()); uuri = UsableURIFactory.getInstance("file://///boo_hoo/wwwroot/CMS/Images1/Banner.gif"); uuri2 = (UsableURI) SerializationUtils.deserialize(SerializationUtils.serialize(uuri)); assertEquals("Not equal", uuri.toString(), uuri2.toString()); }
From source file:org.azrul.langmera.SaveToDB.java
@Override public void start(Future<Void> fut) { HttpServerOptions options = new HttpServerOptions(); options.setReuseAddress(true);/*w w w .jav a 2s . co m*/ JDBCClient client = JDBCClient.createShared(vertx, new JsonObject().put("url", "jdbc:postgresql://localhost:5432/langmeradb") .put("driver_class", "org.postgresql.Driver").put("max_pool_size", 20) .put("user", "Langmera").put("password", "1qazZAQ!")); vertx.eventBus().<byte[]>consumer("SAVE_TRACE_TO_TRACE", message -> { Trace trace = (Trace) SerializationUtils.deserialize(message.body()); client.getConnection(res -> { if (!res.succeeded()) { logger.log(Level.SEVERE, "Problem encountered getting DB connection. Please check DB credentials", res.cause()); } else { SQLConnection connection = res.result(); // String sql = "insert into Trace(context,qvalue,decisionid, decisiontime,decision,score) values(?,?,?,?,?,?)"; // JsonArray input = new JsonArray(). // add(trace.getContext()). // add(trace.getQvalue()). // add(trace.getDecisionId()). // add(trace.getTimeStamp()). // add(trace.getOption()). // add(trace.getScore()); String sql = "insert into Trace(context,qvalue,decisionid, decisiontime,decision,score,maxQ) values('" + trace.getContext() + "'," + trace.getQvalue() + ",'" + trace.getDecisionId() + "','" + trace.getTimeStamp() + "','" + trace.getOption() + "'," + trace.getScore() + "," + trace.getMaxQ() + ")"; //System.out.println("SQL:"+sql); connection.execute(sql, res2 -> { if (res2.failed()) { logger.log(Level.SEVERE, "Problem encountered when saving to DB", res2.cause()); } connection.close(); }); // connection.setAutoCommit(false, // res3->connection.updateWithParams(sql, input, res2 -> { // if (res2.failed()){ // connection.rollback(res5->{ // logger.log(Level.SEVERE, "Problem encountered when saving to DB", res2.cause()); // }); // // }else{ // connection.commit(res4->{ // connection.close(); // }); // } // // })); } }); }); }
From source file:org.brocalc.domain.SerializationTest.java
@Test public void brokerageScheduleShouldSerialize() { Broker broker = new Broker("TestBroker"); BrokerageScheduleFactory brokerageScheduleFactory = new BrokerageScheduleFactory(); BrokerageSchedule brokerageSchedule = brokerageScheduleFactory.createBrokerageSchedule(broker, EXAMPLE_SCHEDULE);/*from w w w . ja v a2s . c om*/ byte[] serializedForm = SerializationUtils.serialize(brokerageSchedule); brokerageSchedule = (BrokerageSchedule) SerializationUtils.deserialize(serializedForm); }
From source file:org.codehaus.httpcache4j.cache.KeyTest.java
@Test public void testSerializationWithEmptyVary() { Key key1 = Key.create(URI.create("foo"), new Vary()); byte[] bytes = SerializationUtils.serialize(key1); Key key2 = (Key) SerializationUtils.deserialize(bytes); Assert.assertEquals(key1, key2);//from ww w .ja va 2 s . c o m }
From source file:org.codehaus.httpcache4j.cache.KeyTest.java
@Test public void testSerializationOneItemInVary() { Key key1 = Key.create(URI.create("foo"), new Vary(Collections.singletonMap("Accept-Language", "en"))); byte[] bytes = SerializationUtils.serialize(key1); Key key2 = (Key) SerializationUtils.deserialize(bytes); Assert.assertEquals(key1, key2);// w w w.j av a 2 s .c o m }
From source file:org.codehaus.httpcache4j.cache.PersistentCacheStorage.java
private void getCacheFromDisk() { if (cache == null) { cache = new InvalidateOnRemoveLRUHashMap(capacity); }//ww w . java2 s. co m if (serializationFile.exists()) { FileInputStream inputStream = null; try { inputStream = FileUtils.openInputStream(serializationFile); cache = (InvalidateOnRemoveLRUHashMap) SerializationUtils.deserialize(inputStream); } catch (Exception e) { serializationFile.delete(); //Ignored, we create a new one. cache = new InvalidateOnRemoveLRUHashMap(capacity); } finally { IOUtils.closeQuietly(inputStream); } } }
From source file:org.codekaizen.vtj.AbstractValueTypeTest.java
/** * Verifies that <code>Serializable</code> is implemented correctly. *///from w ww .j a v a 2s. c om @Test(groups = { "api" }) public final void shouldImplementSerialization() { final ValueType<?> vt1 = getDefaultTestInstance(); final ValueType<?> vt2 = (ValueType<?>) SerializationUtils.deserialize(SerializationUtils.serialize(vt1)); assertEquals(vt2, vt1); }
From source file:org.codekaizen.vtj.hibernate3.AbstractValueTypeUserTypeTest.java
@Test public void shouldSerializeWithoutComplaint() { UserType ut1 = this.newUserTypeInstance(); UserType ut2 = (UserType) SerializationUtils.deserialize(SerializationUtils.serialize((Serializable) ut1)); assertEquals(ut2.returnedClass(), ut1.returnedClass()); }
From source file:org.codekaizen.vtj.text.BpDateFormatTest.java
/** * DOCUMENT ME!/* w ww . j a va 2 s. c o m*/ * * @throws Exception DOCUMENT ME! */ public void testSerialization() throws Exception { BpDateFormat fmt1 = null; BpDateFormat fmt2 = null; fmt1 = new BpDateFormat(BpDateFormat.ISO_DATE_TIME, null); fmt2 = (BpDateFormat) SerializationUtils.deserialize(SerializationUtils.serialize(fmt1)); assertEquals(fmt1, fmt2); }
From source file:org.codekaizen.vtj.text.BpNumberFormatTest.java
/** * DOCUMENT ME!//ww w. j a va 2 s .co m * * @throws Exception DOCUMENT ME! */ @Test public void testSerialization() throws Exception { BpNumberFormat fmt1 = null; BpNumberFormat fmt2 = null; fmt1 = new BpNumberFormat(BpNumberFormat.JVM_CURRENCY, null); fmt2 = (BpNumberFormat) SerializationUtils.deserialize(SerializationUtils.serialize(fmt1)); assertEquals(fmt1, fmt2); }