List of usage examples for org.apache.commons.lang SerializationUtils serialize
public static byte[] serialize(Serializable obj)
Serializes an Object
to a byte array for storage/serialization.
From source file:mitm.application.djigzo.james.EncryptedContainer.java
private void writeObject(ObjectOutputStream out) throws IOException, EncryptorException { out.writeLong(serialVersionUID);/*w ww .ja v a 2 s . c om*/ byte[] encrypted = getEncryptor().encrypt(SerializationUtils.serialize(value)); out.writeInt(ArrayUtils.getLength(encrypted)); out.write(encrypted); }
From source file:com.feedzai.fos.impl.weka.utils.Cloner.java
/** * Creates a clonner by reading a serialized object from file. * * @param descriptor A {@link com.feedzai.fos.api.ModelDescriptor} with the information about the classifier. * @throws IOException when there were problems reading the file *//* w w w. j a va2 s. co m*/ public Cloner(ModelDescriptor descriptor) throws IOException { checkNotNull(descriptor.getModelFilePath(), "Source file cannot be null"); File file = new File(descriptor.getModelFilePath()); checkArgument(file.exists(), "Source file '" + file.getAbsolutePath() + "' must exist"); switch (descriptor.getFormat()) { case BINARY: this.serializedObject = FileUtils.readFileToByteArray(file); break; case PMML: try { this.serializedObject = SerializationUtils.serialize(PMMLConsumers.consume(file)); } catch (FOSException e) { throw new RuntimeException("Failed to consume PMML file.", e); } break; } }
From source file:io.pravega.common.cluster.zkImpl.ClusterZKImpl.java
/** * Register Host to cluster./* www. java 2 s. c om*/ * * @param host Host to be part of cluster. */ @Override @Synchronized public void registerHost(Host host) { Preconditions.checkNotNull(host, "host"); Exceptions.checkArgument(!entryMap.containsKey(host), "host", "host is already registered to cluster."); String hostPath = ZKPaths.makePath(getPathPrefix(), host.toString()); PersistentNode node = new PersistentNode(client, CreateMode.EPHEMERAL, false, hostPath, SerializationUtils.serialize(host)); node.start(); //start creation of ephemeral node in background. entryMap.put(host, node); }
From source file:com.parallax.server.blocklyprop.security.BlocklyPropSessionDao.java
protected SessionRecord convert(Session session) { SimpleSession ssession = (SimpleSession) session; SessionRecord sessionRecord = new SessionRecord(); sessionRecord.setIdsession(session.getId().toString()); sessionRecord.setStarttimestamp(new Timestamp(session.getStartTimestamp().getTime())); sessionRecord.setLastaccesstime(new Timestamp(session.getLastAccessTime().getTime())); sessionRecord.setTimeout(session.getTimeout()); sessionRecord.setHost(session.getHost()); if (ssession.getAttributes() != null) { HashMap<Object, Object> attributes = (HashMap<Object, Object>) ssession.getAttributes(); sessionRecord.setAttributes(SerializationUtils.serialize(attributes)); }//from ww w .j a v a 2 s. c o m return sessionRecord; }
From source file:at.gv.egovernment.moa.id.config.auth.data.BPKDecryptionParameters.java
public byte[] serialize() { return SerializationUtils.serialize(this); }
From source file:es.uvigo.ei.sing.gc.model.entities.ExpertResult.java
public ExpertResult(String classifierName, String geneSetName, String geneSetId, Throwable abortCause) { this.abortCause = SerializationUtils.serialize(abortCause); this.performance = null; this.classifierName = classifierName; this.geneSetName = geneSetName; this.geneSetId = geneSetId; this.selected = false; this.samples = new HashSet<SampleClassification>(); }
From source file:io.tilt.minka.spectator.NodeCacheable.java
/** * Create a child Znode (payload) within another parent (queue) Znode *///from www . j a v a2 s .co m private boolean createOrUpdatePath(final String completeName, final String clientName, final Object payload) { final CuratorFramework client = getClient(); if (client == null) { logger.error("{}: ({}) Cannot use Distributed utilities before setting Zookeeper connection", getClass().getSimpleName(), getLogId()); return false; } boolean result = false; try { //String regenPath = null; final byte[] bytes = SerializationUtils.serialize(new MessageMetadata(payload, clientName)); try { acc += bytes.length; if (logger.isDebugEnabled()) { logger.debug("({}) BYTES SENT: {} (total = {})", getLogId(), bytes.length, acc); } final Collection<CuratorTransactionResult> res = createAndSetZNodeEnsuringPath( CreateMode.PERSISTENT, completeName, 0, bytes); return checkTxGeneratedPath(res) != null; } catch (KeeperException e) { logger.error("{}: ({}) Unexpected while posting message: {}", getClass().getSimpleName(), getLogId(), completeName, e); return false; } } catch (Exception e) { if (isStarted() && isConnected()) { logger.error("{}: ({}) Unexpected while posting message: {}", getClass().getSimpleName(), getLogId(), completeName, e); } else { logger.error("{}: ({}) Zookeeper Disconnection: while posting message: {}", getClass().getSimpleName(), getLogId(), completeName, e.getMessage()); } } return result; }
From source file:com.doculibre.constellio.wicket.models.ReloadableEntityModel.java
@SuppressWarnings("unchecked") private void prepareForSerialization() { if (entity != null) { if (entity.getId() != null) { entityClass = (Class<T>) Hibernate.getClass(entity); id = entity.getId();// w w w .ja v a2s. c om entity = null; serializedEntity = null; } else { serializedEntity = SerializationUtils.serialize((Serializable) entity); entity = null; } } }
From source file:mitm.common.dlp.impl.PolicyViolationImplTest.java
@Test public void testSerializeCollection() { LinkedList<PolicyViolation> violations = new LinkedList<PolicyViolation>(); violations.add(new PolicyViolationImpl("built in", "The message could not be encrypted", null, PolicyViolationPriority.QUARANTINE)); System.out.println(Base64Utils.encodeChunked(SerializationUtils.serialize(violations))); }
From source file:mitm.application.djigzo.james.CertificatesTest.java
@Test public void testSerialize() throws Exception { X509Certificate certificate = TestUtils .loadCertificate(new File("test/resources/testdata/certificates/testcertificate.cer")); Certificates certificates = new Certificates(Collections.singleton(certificate)); assertEquals(1, certificates.getCertificates().size()); byte[] serialized = SerializationUtils.serialize(certificates); Certificates deserialized = (Certificates) SerializationUtils.deserialize(serialized); assertEquals(certificates.getCertificates(), deserialized.getCertificates()); }