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

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

Introduction

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

Prototype

public static byte[] serialize(final Serializable obj) 

Source Link

Document

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

Usage

From source file:org.pascani.dsl.lib.infrastructure.ProbeProxy.java

/**
 * Performs an RPC call to a remote probe
 * /*from  w  ww.  j ava  2  s. c  o m*/
 * @param message
 *            The payload of the message
 * @param defaultValue
 *            A decent value to nicely return in case an {@link Exception}
 *            is thrown
 * @return The response from the RPC server (i.e., a remote component
 *         processing RPC requests) configured with the routing key of the
 *         {@link RpcClient} instance
 */
private byte[] makeActualCall(RpcRequest request, Serializable defaultValue) {
    byte[] message = SerializationUtils.serialize(request);
    byte[] response = SerializationUtils.serialize(defaultValue);
    try {
        response = client.makeRequest(message);
    } catch (Exception e) {
        this.logger.error("Error performing an RPC call to monitor probe " + this.client.routingKey(),
                e.getCause());
        throw new RuntimeException(e);
    }
    return response;
}

From source file:org.pascani.dsl.lib.infrastructure.rabbitmq.RabbitMQProducer.java

@Override
protected void publish(Event<?> event) throws IOException {
    byte[] data = SerializationUtils.serialize(event);
    BasicProperties props = new BasicProperties.Builder().messageId(event.identifier().toString())
            .deliveryMode(2).priority(0).type(event.getClass().getCanonicalName()).build();

    Channel c = endPoint.channel();
    c.basicPublish(this.exchange, this.routingKey, props, data);
}

From source file:org.silverpeas.core.io.temp.TemporaryWorkspaceTranslationTest.java

@Test
public void testWorkspaceExistWithAdditionalData() throws Exception {
    File descriptorSrc = new File(tempPath, (SILVERPEAS_TRANSLATION_PREFIX + TEST_WORKSPACE_ID));
    File workspaceSrc = new File(tempPath, "titititititititititititititititititititititi");
    FileUtils.writeStringToFile(descriptorSrc,
            TRANSLATION_ID_KEY + "titititititititititititititititititititititi");
    FileUtils.writeStringToFile(descriptorSrc,
            "\nkey=" + Base64.encodeBase64String(SerializationUtils.serialize("value")), true);
    workspaceSrc.mkdirs();//from  ww  w .j ava  2  s  . c o  m

    TemporaryWorkspaceTranslation test = TemporaryWorkspaceTranslation.from(TEST_WORKSPACE_ID);
    File descriptor = new File(tempPath, (SILVERPEAS_TRANSLATION_PREFIX + TEST_WORKSPACE_ID));
    File workspace = test.getRootPath();
    assertThat(descriptor, not(is(workspace)));
    assertThat(descriptor, is(descriptorSrc));
    assertThat(workspace, is(workspaceSrc));
    assertThat(test.get("key"), is("value"));
}

From source file:org.silverpeas.core.io.temp.TestTemporaryWorkspaceTranslation.java

@Test
public void testWorkspaceExistWithAdditionalData() throws Exception {
    File descriptorSrc = new File(tempPath, (SILVERPEAS_TRANSLATION_PREFIX + TEST_WORKSPACE_ID));
    File workspaceSrc = new File(tempPath, "titititititititititititititititititititititi");
    FileUtils.writeStringToFile(descriptorSrc,
            TRANSLATION_ID_KEY + "titititititititititititititititititititititi");
    FileUtils.writeStringToFile(descriptorSrc,
            "\nkey=" + Base64.encodeBase64String(SerializationUtils.serialize("value")), true);
    workspaceSrc.mkdirs();/*from w  ww  . ja  v a 2s.  com*/

    TemporaryWorkspaceTranslation test = TemporaryWorkspaceTranslation.from(TEST_WORKSPACE_ID);
    File descriptor = new File(tempPath, (SILVERPEAS_TRANSLATION_PREFIX + TEST_WORKSPACE_ID));
    File workspace = test.getRootPath();
    assertThat(descriptor, not(is(workspace)));
    assertThat(descriptor, is(descriptorSrc));
    assertThat(workspace, is(workspaceSrc));
    assertThat((String) test.get("key"), is("value"));
}

From source file:org.sinekartapdfa.utils.EncodingUtils.java

public static byte[] serialize(Serializable item) {
    return SerializationUtils.serialize(item);
}

From source file:org.sinekartapdfa.utils.EncodingUtils.java

public static String serializeHex(Serializable item) {
    byte[] bytes = SerializationUtils.serialize(item);
    return HexUtils.encodeHex(bytes);
}

From source file:org.sinekartapdfa.utils.EncodingUtils.java

public static String serializeBase64(Serializable item) {
    byte[] bytes = SerializationUtils.serialize(item);
    return Base64.encodeBase64String(bytes);
}

From source file:org.spoutcraft.mod.protocol.codec.AddPrefabCodec.java

@Override
public ByteBuf encode(Spoutcraft game, AddPrefabMessage message) throws IOException {
    if (game.getSide().isClient()) {
        throw new IOException("The client is not allowed to send prefabs");
    }//from   w  w w .  jav a2s  . c  om
    final ByteBuf buffer = Unpooled.buffer();
    BufferUtil.writeUTF8(buffer, message.getAddonIdentifier());
    final byte[] data = SerializationUtils.serialize(message.getPrefab());
    buffer.writeBytes(data);
    return buffer;
}

From source file:org.spoutcraft.mod.protocol.codec.DownloadLinkCodec.java

@Override
public ByteBuf encode(Spoutcraft game, DownloadLinkMessage message) throws IOException {
    if (game.getSide().isClient()) {
        throw new IOException("Client is not allowed to send links!");
    }//from  w w  w .j a v a  2 s. c  o  m
    final String addonIdentifier = message.getAddonIdentifier();
    final URL url = message.getUrl();
    final byte[] data = SerializationUtils.serialize(url);
    final ByteBuf buffer = Unpooled.buffer();
    BufferUtil.writeUTF8(buffer, addonIdentifier);
    buffer.writeBytes(data);
    return buffer;
}

From source file:org.springframework.format.base64.ObjectToBase64StringConverter.java

@Override
public String convert(T source) {
    if (source == null) {
        return "";
    }/*w w w .j  a v a2  s.  c o m*/

    byte[] bytes = SerializationUtils.serialize(source);
    String str = Base64.encodeBase64String(bytes);
    return str;
}