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:uk.ac.diamond.scisoft.analysis.io.UViewDatLoaderTest.java

@Test
public void testSerializability() throws Exception {
    final String testfile = "testfiles/gda/analysis/io/UViewDatLoaderTest/movie_22_000001.dat";
    DataHolder loader = (DataHolder) new UViewDatLoader(testfile).loadFile();
    Dataset data = loader.getDataset(0);
    SerializationUtils.serialize(data.getMetadata());
}

From source file:uk.ac.ebi.interpro.scan.model.ProteinTest.java

/**
 * Tests the serialization and de-serialization works.
 *///  w  w w .  j av  a 2  s .  co  m
@Test
public void testSerialization() throws IOException {

    Protein original = new Protein(GOOD);
    original.addCrossReference(new ProteinXref("A0A000_9ACTO"));

    Set<Hmmer2Match.Hmmer2Location> locations = new HashSet<Hmmer2Match.Hmmer2Location>();
    locations.add(new Hmmer2Match.Hmmer2Location(3, 107, 3.0, 3.7e-9, 1, 104, HmmBounds.N_TERMINAL_COMPLETE));
    original.addMatch(new Hmmer2Match(new Signature("PF02310", "B12-binding"), 0.035, 3.7e-9, locations));

    Set<ProfileScanMatch.ProfileScanLocation> l = new HashSet<ProfileScanMatch.ProfileScanLocation>();
    // Sequence is 60 chars, so make up a CIGAR string that adds up to 60 (10+10+30):
    l.add(new ProfileScanMatch.ProfileScanLocation(1, 60, 15.158, "10M10D10I30M"));
    original.addMatch(new ProfileScanMatch(new Signature("PS50206"), l));

    byte[] data = SerializationUtils.serialize(original);
    String originalXML = marshal(original);
    Object retrieved = SerializationUtils.deserialize(data);
    String unserializedXML = marshal((Protein) retrieved);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(unserializedXML);
        LOGGER.debug("Data lengths serialized: " + data.length + " original xml: " + originalXML.length()
                + " unserialized xml: " + unserializedXML.length());
    }

    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreAttributeOrder(true);
    XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
    XMLUnit.setNormalizeWhitespace(true);
    assertEquals(originalXML, unserializedXML);
}

From source file:uk.bl.wa.hadoop.indexer.WritableSolrRecord.java

@Override
public void write(DataOutput output) throws IOException {
    byte[] bytes = SerializationUtils.serialize(this.sr.getSolrDocument());
    output.writeInt(bytes.length);//from  w w w.j av a  2s .  c  o  m
    output.write(bytes);
}

From source file:ws.prager.camel.consul.ConsulRegistry.java

public void put(String key, Object object) {
    // Substitute $ character in key
    key = key.replaceAll("\\$", "/");
    // create session to avoid conflicts
    // (not sure if that is safe enough, again)
    SessionClient sessionClient = consul.sessionClient();
    String sessionName = "session_" + UUID.randomUUID().toString();
    SessionCreatedResponse response = sessionClient
            .createSession(ImmutableSession.builder().name(sessionName).build());
    String sessionId = response.getId();
    kvClient = consul.keyValueClient();// w  w w  .  ja  v a2  s .  c o m
    String lockKey = "lock_" + key;
    kvClient.acquireLock(lockKey, sessionName, sessionId);

    // Allow only unique keys, last one wins
    if (lookupByName(key) != null) {
        remove(key);
    }
    Object clone = SerializationUtils.clone((Serializable) object);
    byte[] serializedObject = SerializationUtils.serialize((Serializable) clone);
    // pre-encode due native encoding issues
    byte[] preEncodedValue = Base64.encodeBase64(serializedObject);
    String value = new String(preEncodedValue);
    // store the actual class
    logger.debug("store value: " + value + " ,under key: " + key);
    kvClient.putValue(key, value);
    // store just as a bookmark
    logger.debug("store bookmark: " + 1 + " ,under key: " + object.getClass().getName().replaceAll("\\$", "/")
            + "/" + key);
    kvClient.putValue(object.getClass().getName().replaceAll("\\$", "/") + "/" + key, "1");
    kvClient.releaseLock(lockKey, sessionId);
}