Example usage for org.apache.commons.lang SerializationUtils serialize

List of usage examples for org.apache.commons.lang SerializationUtils serialize

Introduction

In this page you can find the example usage for org.apache.commons.lang SerializationUtils serialize.

Prototype

public static byte[] serialize(Serializable obj) 

Source Link

Document

Serializes an Object to a byte array for storage/serialization.

Usage

From source file:com.impetus.ankush.common.domain.Service.java

public void setData(HashMap<String, Object> data) {
    setDataBytes(SerializationUtils.serialize(data));
}

From source file:io.pravega.segmentstore.server.host.ZKSegmentContainerMonitorTest.java

@Test
public void testStartAndStopContainer() throws Exception {
    @Cleanup/*from w w w  .  j  a  v  a2 s  .  c o  m*/
    CuratorFramework zkClient = startClient();
    initializeHostContainerMapping(zkClient);

    SegmentContainerRegistry containerRegistry = createMockContainerRegistry();
    @Cleanup
    ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient);
    segMonitor.initialize(Duration.ofSeconds(1));

    // Simulate a container that starts successfully.
    CompletableFuture<ContainerHandle> startupFuture = new CompletableFuture<>();
    ContainerHandle containerHandle = mock(ContainerHandle.class);
    when(containerHandle.getContainerId()).thenReturn(2);
    when(containerRegistry.startContainer(eq(2), any())).thenReturn(startupFuture);

    // Now modify the ZK entry.
    HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH);
    currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2));
    zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData));

    // Container finished starting.
    startupFuture.complete(containerHandle);
    verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any());

    Thread.sleep(2000);
    assertEquals(1, segMonitor.getRegisteredContainers().size());
    assertTrue(segMonitor.getRegisteredContainers().contains(2));

    // Now modify the ZK entry. Remove container 2 and add 1.
    HashMap<Host, Set<Integer>> newMapping = new HashMap<>();
    newMapping.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(1));
    zkClient.setData().forPath(PATH, SerializationUtils.serialize(newMapping));

    // Verify that stop is called and only the newly added container is in running state.
    when(containerRegistry.stopContainer(any(), any())).thenReturn(CompletableFuture.completedFuture(null));
    verify(containerRegistry, timeout(1000).atLeastOnce()).stopContainer(any(), any());

    // Using wait here to ensure the private data structure is updated.
    // TODO: Removing dependency on sleep here and other places in this class
    // - https://github.com/pravega/pravega/issues/1079
    Thread.sleep(2000);
    assertEquals(1, segMonitor.getRegisteredContainers().size());
    assertTrue(segMonitor.getRegisteredContainers().contains(1));
}

From source file:mitm.application.djigzo.james.mock.MockMail.java

@Override
public Serializable setAttribute(String name, Serializable serializable) {
    byte[] serialized = null;

    if (serializable != null) {
        /*// ww  w  .  java 2 s  . c  om
         * Serialize immediately so we know that the object is serializable.
         */
        serialized = SerializationUtils.serialize(serializable);
    }

    attributes.put(name, serialized);

    return serializable;
}

From source file:com.impetus.ankush.common.domain.NodeMonitoring.java

/**
 * Sets the service status.//  w  ww.j  a v a  2 s  .c  o m
 * 
 * @param serviceStatus
 *            the serviceStatus to set
 */
public void setTechnologyServiceStatus(HashMap<String, Map<String, Boolean>> serviceStatus) {
    setTechnologyServiceBytes(SerializationUtils.serialize(serviceStatus));
}

From source file:com.impetus.ankush.common.domain.Operation.java

@Transient
public void setData(HashMap<String, Object> data) {
    setDataBytes(SerializationUtils.serialize(data));
}

From source file:com.liveramp.cascading_ext.bloom.BloomFilter.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeInt(this.numHashes);
    out.writeLong(this.vectorSize);
    out.writeLong(this.numElems);
    out.write(this.bits.getRaw());
    byte[] serializedHashFunction = SerializationUtils.serialize(this.hashFunction);
    out.writeInt(serializedHashFunction.length);
    out.write(serializedHashFunction);/*from  w ww  .j  a v  a  2  s  .  com*/
}

From source file:mitm.common.hibernate.CertificateArrayUserType.java

private byte[] toBytes(Certificate[] certificates) throws CertificateEncodingException {
    /* //from   ww  w .ja  va 2 s.c  o m
     * we need to make encodedCerts a LinkedList and not a List because SerializationUtils.serialize 
     * requires the implementation to be serializable.
     */
    LinkedList<EncodedCertificate> encodedCerts = new LinkedList<EncodedCertificate>();

    for (Certificate certificate : certificates) {
        encodedCerts.add(new EncodedCertificate(certificate));
    }

    return SerializationUtils.serialize(encodedCerts);
}

From source file:mitm.common.security.keystore.hibernate.SerializableKeyEntry.java

/**
 * Serializes this object
 * 
 * @return serialized this
 */
public byte[] serialize() {
    return SerializationUtils.serialize(this);
}

From source file:io.pravega.segmentstore.server.host.ZKSegmentContainerManagerTest.java

private void initializeHostContainerMapping(CuratorFramework zkClient) throws Exception {
    HashMap<Host, Set<Integer>> mapping = new HashMap<>();
    mapping.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(1));
    zkClient.create().creatingParentsIfNeeded().forPath(PATH, SerializationUtils.serialize(mapping));
}

From source file:at.gv.egovernment.moa.id.configuration.data.oa.OABPKEncryption.java

@Override
public String store(OnlineApplication dbOA, AuthenticatedUser authUser, HttpServletRequest request) {
    AuthComponentOA oaAuth = dbOA.getAuthComponentOA();
    if (oaAuth == null) {
        oaAuth = new AuthComponentOA();
        dbOA.setAuthComponentOA(oaAuth);

    }/*ww w.java 2  s  .co m*/
    EncBPKInformation bPKEncDec = oaAuth.getEncBPKInformation();
    if (bPKEncDec == null) {
        bPKEncDec = new EncBPKInformation();
        oaAuth.setEncBPKInformation(bPKEncDec);

    }

    BPKDecryption bPKDec = bPKEncDec.getBPKDecryption();
    if (bPKDec == null) {
        bPKDec = new BPKDecryption();
        bPKEncDec.setBPKDecryption(bPKDec);
    }

    if (isDeletekeyStore()) {
        bPKDec.setIv(null);
        bPKDec.setKeyAlias(null);
        bPKDec.setKeyInformation(null);
        bPKDec.setKeyStoreFileName(null);

    }

    BPKDecryptionParameters keyInfo = new BPKDecryptionParameters();
    if (keyStoreForm != null && keyStoreForm.size() > 0) {
        keyInfo.setKeyAlias(keyAlias);
        keyInfo.setKeyPassword(keyPassword);
        keyInfo.setKeyStorePassword(keyStorePassword);

        Iterator<String> interator = keyStoreForm.keySet().iterator();
        bPKDec.setKeyStoreFileName(interator.next());
        bPKDec.setKeyAlias(keyAlias);
        keyInfo.setKeyStore(keyStoreForm.get(bPKDec.getKeyStoreFileName()));

        //encrypt key information
        byte[] serKeyInfo = SerializationUtils.serialize(keyInfo);
        try {
            EncryptedData encryptkeyInfo = ConfigurationEncryptionUtils.getInstance().encrypt(serKeyInfo);
            bPKDec.setIv(encryptkeyInfo.getIv());
            bPKDec.setKeyInformation(encryptkeyInfo.getEncData());

        } catch (BuildException e) {
            log.error("Configuration encryption FAILED.", e);
            return LanguageHelper.getErrorString("error.general.text", request);

        }
    }

    request.getSession().setAttribute(Constants.SESSION_BPKENCRYPTIONDECRYPTION, null);

    return null;
}