List of usage examples for org.apache.commons.lang SerializationUtils serialize
public static byte[] serialize(Serializable obj)
Serializes an Object
to a byte array for storage/serialization.
From source file:org.mule.util.CaseInsensitiveHashMapTestCase.java
@Test public void testMapSerialization() throws Exception { CaseInsensitiveHashMap map = createTestMap(); doTestMap(map);//from ww w . ja va2 s . c o m byte[] bytes = SerializationUtils.serialize(map); CaseInsensitiveHashMap resultMap = (CaseInsensitiveHashMap) SerializationUtils.deserialize(bytes); doTestMap(resultMap); }
From source file:org.mule.util.CopyOnWriteCaseInsensitiveMapTestCase.java
protected Map<String, Object> serializeAndDeserialize(Map<String, Object> map) { byte[] bytes = SerializationUtils.serialize((Serializable) map); return (Map) SerializationUtils.deserialize(bytes); }
From source file:org.mule.VoidResultTestCase.java
@Test public void testUniqueDeserialization() { VoidResult result = VoidResult.getInstance(); byte[] serialized = SerializationUtils.serialize(result); assertNotNull(serialized);/*from ww w. j a va 2 s . c o m*/ Object deserialized = SerializationUtils.deserialize(serialized); assertSame(deserialized, result); assertEquals(deserialized, result); }
From source file:org.nuclos.server.report.ejb3.ReportFacadeBean.java
private void compileAndSaveXML(NuclosEntity entity, ReportOutputVO reportOutput) throws NuclosReportException { final String sReportXML; try {//from w w w. jav a 2 s . c om sReportXML = new String(reportOutput.getSourceFileContent().getData(), CHARENCODING); } catch (UnsupportedEncodingException ex) { throw new NuclosFatalException(ex); } final JasperReport jr = compileReport(sReportXML); reportOutput.setReportCLS(new ByteArrayCarrier(SerializationUtils.serialize(jr))); MasterDataVO mdvo = MasterDataWrapper.wrapReportOutputVO(reportOutput); try { getMasterDataFacade() .modify(entity.equals(NuclosEntity.REPORT) ? NuclosEntity.REPORTOUTPUT.getEntityName() : NuclosEntity.FORMOUTPUT.getEntityName(), mdvo, null, null); } catch (Exception e) { throw new NuclosReportException(e); } }
From source file:org.nuclos.server.report.ejb3.ReportFacadeBean.java
private void compileAndSaveXML(NuclosEntity entity, SubreportVO subreport) throws NuclosReportException { final String sReportXML; try {//from w w w. j av a2 s . c om sReportXML = new String(subreport.getSourcefileContent().getData(), CHARENCODING); } catch (UnsupportedEncodingException ex) { throw new NuclosFatalException(ex); } final JasperReport jr = compileReport(sReportXML); subreport.setReportCLS(new ByteArrayCarrier(SerializationUtils.serialize(jr))); MasterDataVO mdvo = MasterDataWrapper.wrapSubreportVO(entity, subreport); try { getMasterDataFacade().modify(entity.equals(NuclosEntity.REPORT) ? NuclosEntity.SUBREPORT.getEntityName() : NuclosEntity.SUBFORM.getEntityName(), mdvo, null, null); } catch (Exception e) { throw new NuclosReportException(e); } }
From source file:org.nuxeo.ecm.core.resolver.TestDocumentModelResolver.java
@Test public void testSerialization() throws Exception { // create it// w ww .j a va 2s . c o m DocumentModelResolver resolver = new DocumentModelResolver(); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put(PARAM_STORE, STORE_ID_REF); resolver.configure(parameters); // write it byte[] buffer = SerializationUtils.serialize(resolver); // forget the resolver resolver = null; // read it Object readObject = SerializationUtils.deserialize(buffer); // check it's a dir resolver assertTrue(readObject instanceof DocumentModelResolver); DocumentModelResolver readResolver = (DocumentModelResolver) readObject; // check the configuration Map<String, Serializable> outputParameters = readResolver.getParameters(); assertEquals(STORE_ID_REF, outputParameters.get(PARAM_STORE)); // test it works: validate assertTrue(readResolver.validate(idRef)); // test it works: fetch Object entity = readResolver.fetch(idRef); assertTrue(entity instanceof DocumentModel); assertEquals(doc.getPathAsString(), ((DocumentModel) entity).getPathAsString()); // test it works: getReference assertEquals(idRef, readResolver.getReference(doc)); }
From source file:org.nuxeo.ecm.core.TestDocumentModel.java
@Test public void testSerialization() throws IOException, ClassNotFoundException { DocumentModelImpl original = new DocumentModelImpl("my type"); original.setPrefetch(new Prefetch()); original.attach("somesessionid"); // check it's attached checkAttached(original, true);//from w w w. ja v a 2 s .c o m // write it byte[] buffer = SerializationUtils.serialize(original); original = null; // read it Object rehydrated = SerializationUtils.deserialize(buffer); // check it's a document and it's detached assertNotNull(rehydrated); assertTrue(rehydrated instanceof DocumentModelImpl); checkAttached((DocumentModelImpl) rehydrated, false); }
From source file:org.nuxeo.ecm.directory.TestDirectoryEntryResolver.java
@Test public void testSerialization() throws Exception { // create it//from ww w . ja v a 2s.c o m DirectoryEntryResolver derr = new DirectoryEntryResolver(); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put(PARAM_DIRECTORY, REFERENCED_DIRECTORY1); derr.configure(parameters); // write it byte[] buffer = SerializationUtils.serialize(derr); // forget the resolver derr = null; // read it Object readObject = SerializationUtils.deserialize(buffer); // check it's a dir resolver assertTrue(readObject instanceof DirectoryEntryResolver); DirectoryEntryResolver readDerr = (DirectoryEntryResolver) readObject; // check the configuration assertEquals(REFERENCED_DIRECTORY1, readDerr.getDirectory().getName()); Map<String, Serializable> outputParameters = readDerr.getParameters(); assertEquals(REFERENCED_DIRECTORY1, outputParameters.get(PARAM_DIRECTORY)); // test it works: validate assertTrue(readDerr.validate(ENTRY_ID)); // test it works: fetch Object entity = readDerr.fetch(ENTRY_ID); assertTrue(entity instanceof DirectoryEntry); assertEquals(ENTRY_LABEL, ((DirectoryEntry) entity).getDocumentModel().getPropertyValue("drs:label")); // test it works: getReference assertEquals(ENTRY_ID, readDerr.getReference(entry1)); }
From source file:org.nuxeo.ecm.platform.usermanager.TestUserManagerResolver.java
@Test public void testSerialization() throws Exception { // create it//from w ww. j a v a 2 s . com UserManagerResolver resolver = new UserManagerResolver(); resolver.configure(new HashMap<String, String>()); // write it byte[] buffer = SerializationUtils.serialize(resolver); // forget the resolver resolver = null; // read it Object readObject = SerializationUtils.deserialize(buffer); // check it's a dir resolver assertTrue(readObject instanceof UserManagerResolver); UserManagerResolver readResolver = (UserManagerResolver) readObject; // check the configuration assertTrue(readResolver.isIncludingGroups()); assertTrue(readResolver.isIncludingUsers()); Map<String, Serializable> outputParameters = readResolver.getParameters(); assertEquals(true, outputParameters.get(UserManagerResolver.PARAM_INCLUDE_GROUPS)); assertEquals(true, outputParameters.get(UserManagerResolver.PARAM_INCLUDE_USERS)); // test it works: validate assertTrue(readResolver.validate("user:Administrator")); // test it works: fetch Object entity = readResolver.fetch("user:Administrator"); assertTrue(entity instanceof NuxeoPrincipal); assertEquals("Administrator", ((NuxeoPrincipal) entity).getName()); // test it works: getReference NuxeoPrincipal principal = userManager.getPrincipal("Administrator"); assertEquals("user:Administrator", readResolver.getReference(principal)); }
From source file:org.opendaylight.controller.cluster.access.concepts.AbstractEnvelopeTest.java
@Test public void testProxySerializationDeserialization() throws Exception { final byte[] serializedBytes = SerializationUtils.serialize(envelope); final Object deserialize = SerializationUtils.deserialize(serializedBytes); checkDeserialized((E) deserialize);/* ww w. j ava 2s . c o m*/ }