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:com.romeikat.datamessie.core.base.util.sparsetable.SparseMultiTableTest.java
@Test public void serializeAndDeserialize() throws Exception { final SparseMultiTable<Double, Double, Double> table = new SparseMultiTable<Double, Double, Double>(); for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) { final double rowHeader = Math.random(); final double columnHeader = Math.random(); final double value1 = Math.random(); final double value2 = Math.random(); table.putValue(rowHeader, columnHeader, value1); table.putValue(rowHeader, columnHeader, value2); }/*w w w.j a v a 2 s . c o m*/ final byte[] serializedTable = SerializationUtils.serialize(table); @SuppressWarnings("unchecked") final SparseMultiTable<Double, Double, Double> deserializedTable = (SparseMultiTable<Double, Double, Double>) SerializationUtils .deserialize(serializedTable); assertEquals(table, deserializedTable); }
From source file:at.jps.sanction.model.queue.file.FileQueue.java
@Override public boolean addMessage(final X message) { try {// ww w .j a v a 2 s . c o m getQueue().enqueue(SerializationUtils.serialize((Serializable) message)); flush(); // TODO: this IS ugly ... super.addMessage(message); return true; } catch (final IOException e) { logger.error("Error adding Message:" + e.toString()); logger.debug("Exception: ", e); return false; } }
From source file:com.splicemachine.derby.stream.output.PipelineWriterBuilder.java
public String getHTableWriterBuilderBase64String() throws IOException, StandardException { return Base64.encodeBase64String(SerializationUtils.serialize(this)); }
From source file:com.link_intersystems.lang.reflect.SerializableMethodTest.java
/** * Helper method until commons-lang3 fixed the class loader problem. See * {@link https://issues.apache.org/jira/browse/LANG-788}. *//*from www . ja v a 2 s. co m*/ @SuppressWarnings("unchecked") private static <T extends Serializable> T cloneSerializable(T serializable) { T clone = (T) SerializationUtils.deserialize(SerializationUtils.serialize(serializable)); return clone; }
From source file:com.link_intersystems.util.SerializableTemplateObjectFactory.java
/** * Constructs a new {@link SerializableTemplateObjectFactory} based on the * template object. The template object's state is frozen at construction * time of this {@link SerializableTemplateObjectFactory} so that the * {@link #getObject()} method returns new instances of the template object * whose states reflect the template object's state when this * {@link SerializableTemplateObjectFactory} was constructed. So changes to * the template object after constructing this * {@link SerializableTemplateObjectFactory} will have no effect to this * {@link ObjectFactory}./*from w w w . j av a2 s. co m*/ * * @param template * the template for this {@link ObjectFactory}. */ public SerializableTemplateObjectFactory(T template) { Assert.notNull("template", template); this.template = SerializationUtils.serialize(template); }
From source file:com.iveely.computing.common.StreamPacket.java
/** * Stream packet to bytes. */ public byte[] toBytes() { return SerializationUtils.serialize(this); }
From source file:com.splicemachine.olap.DistributedCompaction.java
public String base64EncodedFileList() { assert files instanceof Serializable : "Non-serializable list specified!"; return Base64.encodeBase64String(SerializationUtils.serialize((Serializable) files)); }
From source file:glluch.com.ontotaxoseeker.TestsGen.java
public void FindPaths_StringResults() throws IOException { System.out.println("TaxoPath findPaths"); String doc = TestsGen.DOC;/*from www . ja v a 2s . c om*/ TaxoPath instance = new TaxoPath(); PathsCount result = instance.findPaths(doc); TermsCount res = result.conceptsCount(); File target = new File("resources/test/FindPaths_StringResults.bin"); byte[] vs = SerializationUtils.serialize(res); FileUtils.writeByteArrayToFile(target, vs); }
From source file:com.francetelecom.clara.cloud.paas.activation.v1.async.listener.amqp.UnexpectedErrorMessageListener.java
@Override public void onMessage(Message message) { log.debug("message received : " + message); TaskStatus payload = (TaskStatus) SerializationUtils.deserialize(message.getBody()); String communicationId = new String(message.getMessageProperties().getCorrelationId()); try {//from w w w .j av a2 s . c o m log.error("unexpected error occured during task polling process; msg details : " + payload); } catch (Exception e) { log.error("Exception occured during task polling process; details : " + e); } MessageProperties props = MessagePropertiesBuilder.newInstance() .setContentType(MessageProperties.CONTENT_TYPE_SERIALIZED_OBJECT) .setMessageId(UUID.randomUUID().toString()).setCorrelationId(communicationId.getBytes()).build(); Message error = MessageBuilder .withBody(SerializationUtils .serialize(new UnexpectedException("Unexpected error with content: " + payload))) .andProperties(props).build(); amqpErrorTemplate.send(error); }
From source file:com.nesscomputing.sequencer.AbstractSequencerTest.java
@Test public void testEmptySerialization() { final S seq = createEmpty(); byte[] bytes = SerializationUtils.serialize(seq); assertEquals(seq, SerializationUtils.deserialize(bytes)); }