本文整理汇总了Java中org.apache.commons.lang.SerializationUtils.clone方法的典型用法代码示例。如果您正苦于以下问题:Java SerializationUtils.clone方法的具体用法?Java SerializationUtils.clone怎么用?Java SerializationUtils.clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.SerializationUtils
的用法示例。
在下文中一共展示了SerializationUtils.clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSerialization
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void testSerialization() {
CommitTransactionReply expected = CommitTransactionReply.instance(DataStoreVersions.CURRENT_VERSION);
Object serialized = expected.toSerializable();
assertEquals("Serialized type", CommitTransactionReply.class, serialized.getClass());
CommitTransactionReply actual = (CommitTransactionReply)SerializationUtils.clone((Serializable) serialized);
assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
}
示例2: testSerialization
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void testSerialization() {
byte[] data = new byte[1000];
for (int i = 0, j = 0; i < data.length; i++) {
data[i] = (byte)j;
if (++j >= 255) {
j = 0;
}
}
ServerConfigurationPayload serverConfig = new ServerConfigurationPayload(Arrays.asList(
new ServerInfo("leader", true), new ServerInfo("follower", false)));
InstallSnapshot expected = new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6,
Optional.<Integer>of(54321), Optional.of(serverConfig));
Object serialized = expected.toSerializable(RaftVersions.CURRENT_VERSION);
assertEquals("Serialized type", InstallSnapshot.class, serialized.getClass());
InstallSnapshot actual = (InstallSnapshot) SerializationUtils.clone((Serializable) serialized);
verifyInstallSnapshot(expected, actual);
expected = new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6);
actual = (InstallSnapshot) SerializationUtils.clone((Serializable) expected.toSerializable(
RaftVersions.CURRENT_VERSION));
verifyInstallSnapshot(expected, actual);
}
示例3: updateBindings
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
public void updateBindings() throws ConnectionException {
// Check if there is a difference
if (getAddress().equals(currentBinding)) {
return;
}
// Remove old binding
try {
if(currentBinding != null) {
ownRegistry.getRegistry().unbind(currentBinding.getName());
}
}
catch (RemoteException | NotBoundException e) {
safeLogMessage("Trying to unbind a non-existent binding: " + currentBinding + " from " + ownRegistry, LogType.WARN);
}
// Add new binding
socket = LocalSocket.connectTo(getAddress());
socket.register(getAddress());
socket.addMessageReceivedHandler(this);
safeLogMessage("Successfully rebounded the binding " + currentBinding + " to " + getAddress(), LogType.DEBUG);
currentBinding = (NodeAddress) SerializationUtils.clone(getAddress());
}
示例4: testSerializationAndDeserializationOfAllDatastoreTypes
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
public void testSerializationAndDeserializationOfAllDatastoreTypes() throws Exception {
final List<UsageAwareDatastore<?>> datastores = new ArrayList<>();
datastores.add(new AccessDatastore("access", "bar.mdb"));
datastores.add(new CsvDatastore("csv", "bar.csv"));
datastores.add(new DbaseDatastore("dbase", "bar.dbf"));
datastores.add(new ExcelDatastore("excel", null, "bar.xls"));
datastores.add(new JdbcDatastore("jdbc", "url"));
datastores.add(new FixedWidthDatastore("fixedwidth", "foo.txt", "UTF8", new int[] { 1, 2, 3 }));
datastores.add(new CompositeDatastore("foo",
Arrays.asList(datastores.get(0), datastores.get(1), datastores.get(3))));
for (final UsageAwareDatastore<?> ds : datastores) {
System.out.println("Cloning datastore: " + ds);
final Object clone = SerializationUtils.clone(ds);
assertEquals(ds, clone);
}
}
示例5: testSerializationAndDeserializationOfDictionaries
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
public void testSerializationAndDeserializationOfDictionaries() throws Exception {
final String[] dictionaryNames = referenceDataCatalog.getDictionaryNames();
for (final String name : dictionaryNames) {
final Dictionary dict = referenceDataCatalog.getDictionary(name);
if (dict instanceof AbstractReferenceData) {
System.out.println("Cloning dictionary: " + dict);
final Object clone = SerializationUtils.clone(dict);
if (!dict.equals(clone)) {
dict.equals(clone);
}
assertEquals(dict, clone);
}
}
}
示例6: mergeConnectionRepository
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
/**
* Merge the given source {@link ConnectionRepository} with the
* existing target. If parameter
* <tt>deep</tt> is set <code>true</code> deep copies of source objects were made.
* <br/>
* Note: Using <tt>deep copy mode</tt> all descriptors will be serialized
* by using the default class loader to resolve classes. This can be problematic
* when classes are loaded by a context class loader.
* <p>
* Note: All classes within the repository structure have to implement
* <code>java.io.Serializable</code> to be able to create a cloned copy.
*/
public void mergeConnectionRepository(
ConnectionRepository targetRepository, ConnectionRepository sourceRepository, boolean deep)
{
List list = sourceRepository.getAllDescriptor();
for (Iterator iterator = list.iterator(); iterator.hasNext();)
{
JdbcConnectionDescriptor jcd = (JdbcConnectionDescriptor) iterator.next();
if (deep)
{
//TODO: adopt copy/clone methods for metadata classes?
jcd = (JdbcConnectionDescriptor) SerializationUtils.clone(jcd);
}
targetRepository.addDescriptor(jcd);
}
}
示例7: testSerialization
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void testSerialization() {
ExecuteRpc expected = ExecuteRpc.from(AbstractRpcTest.TEST_RPC_ID,
AbstractRpcTest.makeRPCInput("serialization-test"));
ExecuteRpc actual = (ExecuteRpc) SerializationUtils.clone(expected);
assertEquals("getRpc", expected.getRpc(), actual.getRpc());
assertEquals("getInputNormalizedNode", expected.getInputNormalizedNode(), actual.getInputNormalizedNode());
}
示例8: canBeSerialized
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void canBeSerialized() throws Exception {
String value = "foo";
FakeSerializableTestRule fakeRule = new FakeSerializableTestRule().value(value);
SerializableRuleList instance = new SerializableRuleList().add(fakeRule);
SerializableRuleList cloned = (SerializableRuleList) SerializationUtils.clone(instance);
assertThat(cloned.rules().size()).isEqualTo(1);
assertThat(cloned.rules().get(0)).isInstanceOf(FakeSerializableTestRule.class)
.isEqualTo(fakeRule);
}
示例9: canBeSerialized
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void canBeSerialized() throws Exception {
String name = "bar";
Description mockDescription = mock(Description.class);
when(mockDescription.getMethodName()).thenReturn(name);
SerializableTestName instance = new SerializableTestName();
instance.starting(mockDescription);
assertThat(instance.getMethodName()).isEqualTo(name);
SerializableTestName cloned = (SerializableTestName) SerializationUtils.clone(instance);
assertThat(cloned.getMethodName()).isEqualTo(name);
}
示例10: testSerialization
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void testSerialization() {
ServerConfigurationPayload expected = new ServerConfigurationPayload(Arrays.asList(new ServerInfo("1", true),
new ServerInfo("2", false)));
ServerConfigurationPayload cloned = (ServerConfigurationPayload) SerializationUtils.clone(expected);
assertEquals("getServerConfig", expected.getServerConfig(), cloned.getServerConfig());
}
示例11: testSerialization
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void testSerialization() {
YangInstanceIdentifier path = TestModel.TEST_PATH;
DeleteModification expected = new DeleteModification(path);
DeleteModification clone = (DeleteModification) SerializationUtils.clone(expected);
assertEquals("getPath", expected.getPath(), clone.getPath());
}
示例12: testSerialization
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void testSerialization() {
RequestVoteReply expected = new RequestVoteReply(5, true);
RequestVoteReply cloned = (RequestVoteReply) SerializationUtils.clone(expected);
assertEquals("getTerm", expected.getTerm(), cloned.getTerm());
assertEquals("isVoteGranted", expected.isVoteGranted(), cloned.isVoteGranted());
}
示例13: testSerialization
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void testSerialization() {
AppendEntriesReply expected = new AppendEntriesReply("follower", 5, true, 100, 4, (short)6);
AppendEntriesReply cloned = (AppendEntriesReply) SerializationUtils.clone(expected);
assertEquals("getTerm", expected.getTerm(), cloned.getTerm());
assertEquals("getFollowerId", expected.getFollowerId(), cloned.getFollowerId());
assertEquals("getLogLastTerm", expected.getLogLastTerm(), cloned.getLogLastTerm());
assertEquals("getLogLastIndex", expected.getLogLastIndex(), cloned.getLogLastIndex());
assertEquals("getPayloadVersion", expected.getPayloadVersion(), cloned.getPayloadVersion());
assertEquals("getRaftVersion", expected.getRaftVersion(), cloned.getRaftVersion());
}
示例14: testCloseTransactionSerialization
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void testCloseTransactionSerialization() {
CloseTransaction expected = new CloseTransaction(DataStoreVersions.CURRENT_VERSION);
Object serialized = expected.toSerializable();
assertEquals("Serialized type", CloseTransaction.class, serialized.getClass());
CloseTransaction actual = (CloseTransaction)SerializationUtils.clone((Serializable) serialized);
assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
}
示例15: testCloseTransactionReplySerialization
import org.apache.commons.lang.SerializationUtils; //导入方法依赖的package包/类
@Test
public void testCloseTransactionReplySerialization() {
CloseTransactionReply expected = new CloseTransactionReply();
Object serialized = expected.toSerializable();
assertEquals("Serialized type", CloseTransactionReply.class, serialized.getClass());
CloseTransactionReply actual = (CloseTransactionReply)SerializationUtils.clone((Serializable) serialized);
assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
}