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:mitm.common.hibernate.EncodedCertificateTest.java
@Test public void testSerialize() throws Exception { byte[] serialized = SerializationUtils.serialize(new EncodedCertificate(certificate)); EncodedCertificate deserialized = (EncodedCertificate) SerializationUtils.deserialize(serialized); assertEquals(certificate, deserialized.getCertificate()); }
From source file:ai.grakn.engine.tasks.manager.redisqueue.RedisTaskStorage.java
@Override public Boolean updateState(TaskState state) { try (Jedis jedis = redis.getResource(); Context ignore = updateTimer.time()) { String key = encodeKey.apply(state.getId().getValue()); LOG.debug("Updating state {}", key); String value = new String(Base64.getEncoder().encode(SerializationUtils.serialize(state)), Charsets.UTF_8);//from ww w . j ava 2 s . co m String status = jedis.setex(key, 60 * 60/*expire time in seconds*/, value); return status.equalsIgnoreCase("OK"); } }
From source file:hws.util.ZkDataMonitor.java
public void create(String path, Serializable data) throws KeeperException, InterruptedException { this.zk.create(path, SerializationUtils.serialize(data), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); }
From source file:com.zia.freshdocs.preference.CMISPreferencesManager.java
protected void storePreferences(Context ctx, Map<String, CMISHost> map) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx); byte[] encPrefs = Base64.encodeBase64(SerializationUtils.serialize((Serializable) map)); Editor prefsEditor = sharedPrefs.edit(); prefsEditor.putString(SERVERS_KEY, new String(encPrefs)); // indicate that user prefs are set prefsEditor.putBoolean(PREFS_SET_KEY, true); prefsEditor.commit();/*from w w w . j a v a2 s .c om*/ }
From source file:com.smartitengineering.jetty.session.replication.impl.hbase.SessionDataObjectConverter.java
@Override protected void getPutForTable(SessionData instance, ExecutorService service, Put put) { if (instance == null) { return;/*from ww w. j a v a 2 s. co m*/ } instance.setLastSaved(System.currentTimeMillis()); put.add(FAMILY_SELF, CELL_ACCESSED, Bytes.toBytes(instance.getAccessed())); put.add(FAMILY_SELF, CELL_COOKIE_SET, Bytes.toBytes(instance.getCookieSet())); put.add(FAMILY_SELF, CELL_CREATED, Bytes.toBytes(instance.getCreated())); put.add(FAMILY_SELF, CELL_EXPIRY_TIME, Bytes.toBytes(instance.getExpiryTime())); put.add(FAMILY_SELF, CELL_LAST_ACCESSED, Bytes.toBytes(instance.getLastAccessed())); put.add(FAMILY_SELF, CELL_LAST_NODE, Bytes.toBytes(instance.getLastNode())); put.add(FAMILY_SELF, CELL_LAST_SAVED, Bytes.toBytes(instance.getLastSaved())); put.add(FAMILY_SELF, CELL_MAX_IDLE_MS, Bytes.toBytes(instance.getMaxIdleMs())); Map attrs = instance.getAttributeMap(); if (attrs != null && !attrs.isEmpty()) { if (logger.isInfoEnabled()) { logger.info("Serialzed attributes " + attrs); } put.add(FAMILY_SELF, CELL_ATTRIBUTE_MAP, SerializationUtils.serialize((Serializable) attrs)); } else { logger.info("No attributes to serialize"); } }
From source file:mitm.common.dlp.impl.PolicyViolationImplTest.java
@Test public void testSerializeNulls() { PolicyViolation violation = new PolicyViolationImpl(null, null, null, null); byte[] serialized = SerializationUtils.serialize(violation); assertEquals(SERIALIZED_NULLS, MiscStringUtils.toAsciiString((Base64.encodeBase64(serialized)))); violation = (PolicyViolation) SerializationUtils.deserialize(serialized); }
From source file:com.moz.fiji.schema.mapreduce.FijiTableInputFormat.java
/** * Configures a Hadoop M/R job to read from a given table. * * @param job Job to configure.//w w w . j a v a 2 s . c o m * @param tableURI URI of the table to read from. * @param dataRequest Data request. * @param startRow Minimum row key to process. * @param endRow Maximum row Key to process. * @throws IOException on I/O error. */ public static void configureJob(Job job, FijiURI tableURI, FijiDataRequest dataRequest, String startRow, String endRow) throws IOException { final Configuration conf = job.getConfiguration(); // As a precaution, be sure the table exists and can be opened. final Fiji fiji = Fiji.Factory.open(tableURI, conf); final FijiTable table = fiji.openTable(tableURI.getTable()); ResourceUtils.releaseOrLog(table); ResourceUtils.releaseOrLog(fiji); // TODO: Check for jars config: // GenericTableMapReduceUtil.initTableInput(hbaseTableName, scan, job); // TODO: Obey specified start/end rows. // Write all the required values to the job's configuration object. job.setInputFormatClass(FijiTableInputFormat.class); final String serializedRequest = Base64.encodeBase64String(SerializationUtils.serialize(dataRequest)); conf.set(FijiConfKeys.INPUT_DATA_REQUEST, serializedRequest); conf.set(FijiConfKeys.INPUT_TABLE_URI, tableURI.toString()); }
From source file:com.impetus.ankush.common.domain.NodeMonitoring.java
/** * Sets the monitoring info./* w w w . j a va 2 s.c om*/ * * @param monitoringInfo * the monitoringInfo to set */ public void setMonitoringInfo(MonitoringInfo monitoringInfo) { setMonitoringInfoBytes(SerializationUtils.serialize(monitoringInfo)); }
From source file:mitm.common.mail.MailAddressTest.java
@Test public void testSerialize() throws Exception { MailAddress address = new MailAddress("test@example.com"); byte[] serialized = SerializationUtils.serialize(address); MailAddress copy = (MailAddress) SerializationUtils.deserialize(serialized); assertEquals(address, copy);/* w ww . j ava2s .c o m*/ }
From source file:io.pravega.service.server.host.ZKSegmentContainerMonitorTest.java
@Test public void testStartAndStopContainer() throws Exception { @Cleanup//from ww w. ja va 2s.c o m CuratorFramework zkClient = startClient(); initializeHostContainerMapping(zkClient); SegmentContainerRegistry containerRegistry = createMockContainerRegistry(); @Cleanup ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient); segMonitor.initialize(Duration.ofSeconds(1)); // Simulate a container that starts successfully. CompletableFuture<ContainerHandle> startupFuture = new CompletableFuture<>(); ContainerHandle containerHandle = mock(ContainerHandle.class); when(containerHandle.getContainerId()).thenReturn(2); when(containerRegistry.startContainer(eq(2), any())).thenReturn(startupFuture); // Now modify the ZK entry. HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH); currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2)); zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData)); // Container finished starting. startupFuture.complete(containerHandle); verify(containerRegistry, timeout(10000).atLeastOnce()).startContainer(eq(2), any()); Thread.sleep(2000); assertEquals(1, segMonitor.getRegisteredContainers().size()); assertTrue(segMonitor.getRegisteredContainers().contains(2)); // Now modify the ZK entry. Remove container 2 and add 1. HashMap<Host, Set<Integer>> newMapping = new HashMap<>(); newMapping.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(1)); zkClient.setData().forPath(PATH, SerializationUtils.serialize(newMapping)); // Verify that stop is called and only the newly added container is in running state. when(containerRegistry.stopContainer(any(), any())).thenReturn(CompletableFuture.completedFuture(null)); verify(containerRegistry, timeout(10000).atLeastOnce()).stopContainer(any(), any()); // Using wait here to ensure the private data structure is updated. // TODO: Removing dependency on sleep here and other places in this class // - https://github.com/pravega/pravega/issues/1079 Thread.sleep(2000); assertEquals(1, segMonitor.getRegisteredContainers().size()); assertTrue(segMonitor.getRegisteredContainers().contains(1)); }