List of usage examples for org.apache.commons.lang3 SerializationUtils serialize
public static void serialize(final Serializable obj, final OutputStream outputStream)
Serializes an Object to the specified stream.
The stream will be closed once the object is written.
From source file:org.omnaest.utils.beans.copier.PreparedBeanCopierTest.java
@Test @SuppressWarnings("unchecked") public void testDeepClonePropertiesSerializable() { ////from ww w . j av a 2 s.com final ByteArrayContainer byteArrayContainer = new ByteArrayContainer(); SerializationUtils.serialize(this.preparedBeanCopier, byteArrayContainer.getOutputStream()); PreparedBeanCopier<ITestBeanFrom, ITestBeanTo> preparedBeanCopierClone = (PreparedBeanCopier<ITestBeanFrom, ITestBeanTo>) SerializationUtils .deserialize(byteArrayContainer.getInputStream()); // ITestBeanTo clone = preparedBeanCopierClone.deepCloneProperties(this.testBeanFrom); assertTestBeanClone(clone); }
From source file:org.opendaylight.controller.cluster.datastore.admin.ClusterAdminRpcService.java
private static void saveSnapshotsToFile(DatastoreSnapshotList snapshots, String fileName, SettableFuture<RpcResult<Void>> returnFuture) { try (FileOutputStream fos = new FileOutputStream(fileName)) { SerializationUtils.serialize(snapshots, fos); returnFuture.set(newSuccessfulResult()); LOG.info("Successfully backed up datastore to file {}", fileName); } catch (Exception e) { onDatastoreBackupFailure(fileName, returnFuture, e); }/* w w w .ja v a 2s . c o m*/ }
From source file:org.opendaylight.controller.cluster.datastore.DatastoreSnapshotRestoreTest.java
@Test public void test() throws Exception { assertTrue("Failed to mkdir " + restoreDirectoryPath, restoreDirectoryFile.mkdirs()); List<ShardSnapshot> shardSnapshots = new ArrayList<>(); shardSnapshots.add(new ShardSnapshot("cars", new byte[] { 1, 2 })); shardSnapshots.add(new ShardSnapshot("people", new byte[] { 3, 4 })); DatastoreSnapshot configSnapshot = new DatastoreSnapshot("config", null, shardSnapshots); shardSnapshots = new ArrayList<>(); shardSnapshots.add(new ShardSnapshot("cars", new byte[] { 5, 6 })); shardSnapshots.add(new ShardSnapshot("people", new byte[] { 7, 8 })); shardSnapshots.add(new ShardSnapshot("bikes", new byte[] { 9, 0 })); DatastoreSnapshot operSnapshot = new DatastoreSnapshot("oper", null, shardSnapshots); DatastoreSnapshotList snapshotList = new DatastoreSnapshotList(); snapshotList.add(configSnapshot);// www . j a v a2s . c o m snapshotList.add(operSnapshot); File backupFile = new File(restoreDirectoryFile, "backup"); try (FileOutputStream fos = new FileOutputStream(backupFile)) { SerializationUtils.serialize(snapshotList, fos); } DatastoreSnapshotRestore instance = DatastoreSnapshotRestore.instance(restoreDirectoryPath); verifySnapshot(configSnapshot, instance.getAndRemove("config")); verifySnapshot(operSnapshot, instance.getAndRemove("oper")); assertNull("DatastoreSnapshot was not removed", instance.getAndRemove("config")); assertFalse(backupFile + " was not deleted", backupFile.exists()); instance = DatastoreSnapshotRestore.instance(restoreDirectoryPath); assertNull("Expected null DatastoreSnapshot", instance.getAndRemove("config")); assertNull("Expected null DatastoreSnapshot", instance.getAndRemove("oper")); }
From source file:org.opendaylight.controller.cluster.example.ExampleActor.java
@Override @SuppressWarnings("checkstyle:IllegalCatch") public void createSnapshot(ActorRef actorRef, java.util.Optional<OutputStream> installSnapshotStream) { try {//from www .j a va 2 s. c o m if (installSnapshotStream.isPresent()) { SerializationUtils.serialize((Serializable) state, installSnapshotStream.get()); } } catch (RuntimeException e) { LOG.error("Exception in creating snapshot", e); } getSelf().tell(new CaptureSnapshotReply(new MapState(state), installSnapshotStream), null); }