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.sylvanaar.idea.Lua.lang.psi.stubs.elements.LuaTableStubType.java

@Override
public LuaTableStub createStub(@NotNull LuaTableConstructor psi, StubElement parentStub) {
    assert psi.getLuaType() instanceof LuaTable;
    //        if (((LuaTable) psi.getLuaType()).getFieldSet().size() > 0)
    return new LuaTableStubImpl(parentStub, SerializationUtils.serialize(psi.getLuaType()));

    //        return new LuaTableStubImpl(parentStub);
}

From source file:net.datenwerke.transloader.clone.SerializationCloningStrategy.java

/**
 * {@inheritDoc}/*from  www . j  a  v a  2s.  c  om*/
 *
 * @throws ClassCastException     if the given <code>original</code> object is not {@link Serializable}
 * @throws SerializationException if serialization fails
 * @throws IOException            if input fails during deserialization
 * @throws ClassNotFoundException if the <code>targetClassLoader</code> cannot find a required class
 */
public Object cloneObjectUsing(ClassLoader targetLoader, Object original)
        throws ClassCastException, SerializationException, IOException, ClassNotFoundException {
    Assert.areNotNull(targetLoader, original);
    byte[] serializedOriginal = SerializationUtils.serialize((Serializable) original);
    return deserialize(serializedOriginal, targetLoader);
}

From source file:com.ikanow.aleph2.core.shared.utils.TestBatchRecordUtils.java

@Test
public void check_batchRecordIsSerializable() throws IOException {

    final ObjectNode test_json = BeanTemplateUtils.configureMapper(Optional.empty()).createObjectNode();

    test_json.put("test", "test");

    final ByteArrayOutputStream test_out = new ByteArrayOutputStream();
    test_out.write("test2".getBytes());

    {//  w  w w . j  av a  2  s. c o m
        final IBatchRecord test_case = new BatchRecordUtils.BatchRecord(test_json, null);

        final byte[] phase1 = SerializationUtils.serialize((Serializable) test_case);

        final IBatchRecord phase2 = (IBatchRecord) SerializationUtils.deserialize(phase1);

        assertEquals("{\"test\":\"test\"}", phase2.getJson().toString());
    }
    {
        final IBatchRecord test_case = new BatchRecordUtils.JsonBatchRecord(test_json);

        final byte[] phase1 = SerializationUtils.serialize((Serializable) test_case);

        final IBatchRecord phase2 = (IBatchRecord) SerializationUtils.deserialize(phase1);

        assertEquals("{\"test\":\"test\"}", phase2.getJson().toString());
    }
    {
        final IBatchRecord test_case = new BatchRecordUtils.BatchRecord(test_json, test_out);

        final byte[] phase1 = SerializationUtils.serialize((Serializable) test_case);

        final IBatchRecord phase2 = (IBatchRecord) SerializationUtils.deserialize(phase1);

        assertEquals("{\"test\":\"test\"}", phase2.getJson().toString());
        assertEquals("test2", phase2.getContent().get().toString());
    }
    {
        final IBatchRecord test_case = new BatchRecordUtils.BatchRecord(test_json, test_out);
        final Tuple2<Long, IBatchRecord> test_t2 = Tuples._2T(3L, test_case);

        final byte[] phase1 = SerializationUtils.serialize(test_t2);
        @SuppressWarnings("unchecked")
        final Tuple2<Long, IBatchRecord> phase2 = (Tuple2<Long, IBatchRecord>) SerializationUtils
                .deserialize(phase1);

        assertEquals(3L, phase2._1().longValue());
        assertEquals("{\"test\":\"test\"}", phase2._2().getJson().toString());
        assertEquals("test2", phase2._2().getContent().get().toString());
    }
}

From source file:com.shigengyu.hyperion.core.WorkflowContextBinarySerializer.java

@Override
public String serialize(WorkflowContext workflowContext) {
    return Base64.encodeBase64String(SerializationUtils.serialize(workflowContext));
}

From source file:br.com.ufjf.labredes.rest.EleitorResource.java

@POST
@Path("/{eleitor}")
//3. Envia Credenciais
public String login(@PathParam("eleitor") String elector) {
    byte[] elector_decoded = Base64.getDecoder().decode(elector);
    SealedObject aux = (SealedObject) SerializationUtils.deserialize(elector_decoded);
    Eleitor eleitor = (Eleitor) rsa.decrypt(aux, client_aes);
    eleitor = eleitorService.getEleitor(eleitor.getCpf(), eleitor.getSenha());

    Response ans = new Response();
    CandidatoList candidatos = new CandidatoList();

    if (eleitor != null) {
        //3.1 Responde
        candidatos.setCandidatos(candidatoService.getAll());
        byte[] data = SerializationUtils.serialize(rsa.encrypt(candidatos, client_aes));
        String retorno = Base64.getEncoder().encodeToString(data);
        return retorno;
    } else {/*w w  w  . ja v a2s . c  o  m*/
        ans.Error("Erro ao decriptar chave");
        //3.1 Responde
        byte[] data = SerializationUtils.serialize(rsa.encrypt(ans, client_aes));
        String retorno = Base64.getEncoder().encodeToString(data);
        return retorno;
    }

}

From source file:mitm.application.djigzo.mail.MailSerializer.java

/**
 * Serializes the Mail object. /*from ww  w.  j  a va 2s .c  om*/
 * 
 * Note: the MimeMessage is not serialized
 */
public byte[] serialize(Mail mail) {
    if (mail == null) {
        return null;
    }

    return SerializationUtils.serialize(new MailContainer(mail));
}

From source file:io.pravega.controller.store.host.ZKHostStore.java

@Synchronized
private void tryInit() {
    if (!zkInit) {
        ZKUtils.createPathIfNotExists(zkClient, zkPath,
                SerializationUtils.serialize(new HashMap<Host, Set<Integer>>()));
        zkInit = true;//w  w  w  . jav  a2s  .com
    }
}

From source file:com.sylvanaar.idea.Lua.lang.psi.stubs.elements.LuaStubGlobalDeclarationType.java

@Override
public LuaGlobalDeclarationStub createStub(@NotNull LuaGlobalDeclaration psi, StubElement parentStub) {
    final LuaType luaType = psi.getLuaType();
    final byte[] bytes = (luaType instanceof LuaPrimitiveType) ? null : SerializationUtils.serialize(luaType);

    return new LuaGlobalDeclarationStubImpl(parentStub, StringRef.fromNullableString(psi.getName()),
            StringRef.fromNullableString(psi.getModuleName()), bytes, luaType);
}

From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessorTest.java

@Test
public void testReadObject() throws NoSuchFieldException, IllegalAccessException {
    AbstractStAXProcessor<?> abstractStAXProcessor = spy(AbstractStAXProcessor.class);

    final Field field = ReflectionTestUtils.getAccessibleField(AbstractStAXProcessor.class, "xmlInputFactory");
    assertThat(field.get(abstractStAXProcessor), is(notNullValue()));

    // Serialise then deserialise the spy and check the XMLInputFactory has been recreated...
    final byte[] serialisedSpy = SerializationUtils.serialize(abstractStAXProcessor);
    abstractStAXProcessor = (AbstractStAXProcessor<?>) SerializationUtils.deserialize(serialisedSpy);
    assertThat(field.get(abstractStAXProcessor), is(notNullValue()));
}

From source file:mitm.application.djigzo.james.EncryptedContainerTest.java

@SuppressWarnings("unchecked")
@Test/*from w  ww  .j  av a2 s. com*/
public void testSerialize() throws Exception {
    EncryptedContainer<String> container = new EncryptedContainer<String>();

    container.set("123");

    byte[] serialized = SerializationUtils.serialize(container);

    container = (EncryptedContainer<String>) SerializationUtils.deserialize(serialized);

    assertEquals("123", container.get());
}