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:server.Worker.java

/**
 * @param args/*w  w  w.ja  v a  2  s  .  co m*/
 * @throws IOException
 * @throws TimeoutException
 */
public static void main(String[] args) throws IOException, TimeoutException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection requestConnection = factory.newConnection();
    Channel requestChannel = requestConnection.createChannel();
    requestChannel.queueDeclare(REQUEST_QUEUE_NAME, false, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    Connection responseConnection = factory.newConnection();
    final Channel responseChannel = responseConnection.createChannel();
    responseChannel.queueDeclare(RESPONSE_QUEUE_NAME, false, false, false, null);

    Consumer consumer = new DefaultConsumer(requestChannel) {
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                byte[] body) throws IOException {
            PriorityRequest request = (PriorityRequest) SerializationUtils.deserialize(body);
            System.out.println(" [x] Received");
            System.out.println(request.request.toString());
            System.out.println("*************************************");

            System.out.println(request.request.getMethod());
            HttpResponse response = PluginManager.getInstance().process(request.request, request.rootDir);
            if (response == null) {
                response = HttpResponseFactory.create400BadRequest(Protocol.CLOSE);
            }
            try {
                System.out.println(request.id);
            } catch (Exception e) {
                e.printStackTrace();
            }

            response.id = request.id;

            byte[] data = SerializationUtils.serialize(response);
            responseChannel.basicPublish("", RESPONSE_QUEUE_NAME, null, data);
        }
    };
    requestChannel.basicConsume(REQUEST_QUEUE_NAME, true, consumer);
}

From source file:stroom.statistics.common.TestTimeAgnosticStatisticEvent.java

@Test
public void serialiseTest() {
    final List<StatisticTag> tagList = new ArrayList<StatisticTag>();
    tagList.add(new StatisticTag("tag1", "val1"));
    tagList.add(new StatisticTag("tag2", "val2"));

    final TimeAgnosticStatisticEvent timeAgnosticStatisticEvent = new TimeAgnosticStatisticEvent("MtStatName",
            tagList, 42L);/*from www.  j  a v a  2 s  .  c  o m*/

    // if we can't serialise the object then we should get an exception here
    final byte[] serializedForm = SerializationUtils.serialize(timeAgnosticStatisticEvent);

    final TimeAgnosticStatisticEvent timeAgnosticStatisticEvent2 = (TimeAgnosticStatisticEvent) SerializationUtils
            .deserialize(serializedForm);

    Assert.assertEquals(timeAgnosticStatisticEvent, timeAgnosticStatisticEvent2);
}

From source file:stroom.statistics.server.sql.TestTimeAgnosticStatisticEvent.java

@Test
public void serialiseTest() {
    final List<StatisticTag> tagList = new ArrayList<>();
    tagList.add(new StatisticTag("tag1", "val1"));
    tagList.add(new StatisticTag("tag2", "val2"));

    final TimeAgnosticStatisticEvent timeAgnosticStatisticEvent = TimeAgnosticStatisticEvent
            .createCount("MtStatName", tagList, 42L);

    // if we can't serialise the object then we should get an exception here
    final byte[] serializedForm = SerializationUtils.serialize(timeAgnosticStatisticEvent);

    final TimeAgnosticStatisticEvent timeAgnosticStatisticEvent2 = (TimeAgnosticStatisticEvent) SerializationUtils
            .deserialize(serializedForm);

    Assert.assertEquals(timeAgnosticStatisticEvent, timeAgnosticStatisticEvent2);
}

From source file:uk.ac.diamond.scisoft.analysis.io.CBFLoaderTest.java

@Test
public void testSerializability() throws Exception {
    DataHolder loader = new CBFLoader(testpath + "xtal5e_1_0010.cbf").loadFile();
    Dataset data = loader.getDataset(0);
    SerializationUtils.serialize(data.getMetadata());
}

From source file:uk.ac.diamond.scisoft.analysis.io.CrysalisLoaderTest.java

@Test
public void testSerializability() throws Exception {
    DataHolder loader = new CrysalisLoader(TestFileFolder + "ccd_direct_0deg_1000ms_1.img_1_uncomp.img")
            .loadFile();/*from   w  ww  .jav  a 2  s .  co  m*/
    Dataset data = loader.getDataset(0);
    SerializationUtils.serialize(data.getMetadata());
}

From source file:uk.ac.diamond.scisoft.analysis.io.DatLoaderTest.java

@Test
public void testSerializability() throws Exception {
    DataHolder loader = new DatLoader("testfiles/gda/analysis/io/DatLoaderTest/MoFoil.dat").loadFile();
    Dataset data = loader.getDataset(0);
    SerializationUtils.serialize(data.getMetadata());
}

From source file:uk.ac.diamond.scisoft.analysis.io.DiffractionImageTest.java

@Test
public void testSerializability() throws Exception {
    Dataset data;/*from ww  w  .j  a  v  a  2 s. c o m*/
    data = new ADSCImageLoader(testfile1).loadFile().getDataset(0);
    SerializationUtils.serialize(data.getMetadata());

    data = new MARLoader(testfile2).loadFile().getDataset(0);
    SerializationUtils.serialize(data.getMetadata());

    data = new CBFLoader(testfile3).loadFile().getDataset(0);
    SerializationUtils.serialize(data.getMetadata());
}

From source file:uk.ac.diamond.scisoft.analysis.io.MARImageTest.java

@Test
public void testSerializability() throws Exception {
    DataHolder loader = new MARLoader(testfile2).loadFile();
    Dataset data = loader.getDataset(0);
    SerializationUtils.serialize(data.getMetadata());
}

From source file:uk.ac.diamond.scisoft.analysis.io.RAxisImageLoaderTest.java

@Test
public void testSerializability() throws Exception {
    DataHolder loader = new RAxisImageLoader(filename).loadFile();
    Dataset data = loader.getDataset(0);
    SerializationUtils.serialize(data.getMetadata());
}

From source file:uk.ac.diamond.scisoft.analysis.io.SRSLoaderTest.java

@Test
public void testSerializability() throws Exception {
    DataHolder dh = new SRSLoader("testfiles/gda/analysis/io/SRSLoaderTest/96356.dat").loadFile();
    Dataset data = dh.getDataset(0);//from   w w w  . j  a va2  s.c  o m
    SerializationUtils.serialize(data.getMetadata());
}