本文整理汇总了Java中org.nustaq.serialization.FSTConfiguration.asObject方法的典型用法代码示例。如果您正苦于以下问题:Java FSTConfiguration.asObject方法的具体用法?Java FSTConfiguration.asObject怎么用?Java FSTConfiguration.asObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.nustaq.serialization.FSTConfiguration
的用法示例。
在下文中一共展示了FSTConfiguration.asObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
SomeMediumClass mediumClass = new SomeMediumClass();
byte barray[] = conf.asByteArray(mediumClass);
System.out.println(barray.length);
SomeMediumClass object = (SomeMediumClass)conf.asObject(barray);
System.out.println(object);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
FSTObjectOutput output = new FSTObjectOutput(outputStream);
output.writeObject(mediumClass);
output.close();
FSTObjectInput input = new FSTObjectInput(new ByteArrayInputStream(outputStream.toByteArray()));
object = (SomeMediumClass)input.readObject(SomeMediumClass.class);
System.out.println(object);
}
示例2: test
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
// install BouncyCastle provider
Security.addProvider(new BouncyCastleProvider());
// generate a keypair
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA", "BC");
RSAKeyGenParameterSpec params = new RSAKeyGenParameterSpec(STRENGTH, PUBLIC_EXP);
gen.initialize(params, new SecureRandom());
KeyPair keyPair = gen.generateKeyPair();
FSTConfiguration fst = FSTConfiguration.createDefaultConfiguration();
// serialize
byte[] serialized = fst.asByteArray(keyPair);
// deserialize --> crash
KeyPair deserialized = (KeyPair) fst.asObject(serialized);
}
示例3: testUnmodifiableLinkedHashMap
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void testUnmodifiableLinkedHashMap() {
FSTConfiguration conf = getConfiguration();
Map m1 = new LinkedHashMap<String, Integer>();
m1.put("a", 1);
m1.put("BB", 1);
m1.put("ccc", 1);
m1.put("aa", 1);
m1.put("BBa", 1);
m1.put("ccca", 1);
m1 = Collections.unmodifiableMap(m1);
Map un = Collections.unmodifiableMap(m1);
Map res = (Map) conf.asObject(conf.asByteArray(un));
assertTrue(DeepEquals.deepEquals(res,un));
System.out.println(res.keySet());
System.out.println(m1.keySet());
}
示例4: testUnshared
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void testUnshared() {
Set<Long> obj = new LinkedHashSet<>();
obj.add(11373L);
FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
conf.setShareReferences(false);
conf.registerSerializer(LinkedHashSet.class,new FSTCollectionSerializer(),true);
byte[] bytes = conf.asByteArray(obj);
Object o = conf.asObject(bytes);
}
示例5: test
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
Object[] x = { Duration.ofDays(1), Duration.ofDays(2) };
Object[] res = (Object[]) conf.asObject(conf.asByteArray(x));
Assert.assertTrue( x[0].equals(res[0]) && x[1].equals(res[1]));
}
示例6: serializationTest
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void serializationTest() throws IOException, ClassNotFoundException {
// Instantiation of the ExternalizableTestClass object
int integer = 10;
String path = "path";
ExternalizableTestClass object = new ExternalizableTestClass(integer, path);
// when serialized and deserialized, the integer value should be
// overwritten by readResolve and set to 1.
// Java
// 1. serialize
byte[] data1;
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(bos)) {
out.writeObject(object);
data1 = bos.toByteArray();
}
// 2. deserialize
ExternalizableTestClass object1;
try (ByteArrayInputStream bis = new ByteArrayInputStream(data1); ObjectInput in = new ObjectInputStream(bis)) {
object1 = (ExternalizableTestClass) in.readObject();
}
Assert.assertEquals(1, object1.getInteger());
// FST
// 1. serialize
FSTConfiguration config = FSTConfiguration.createDefaultConfiguration();
byte[] data2 = config.asByteArray(object);
// 2. deserialize
ExternalizableTestClass object2 = (ExternalizableTestClass) config.asObject(data2);
Assert.assertEquals(1, object2.getInteger());
}
示例7: test
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
public void test( FSTConfiguration conf, Serializable toTest ) {
byte b[] = conf.asByteArray(toTest);
Object deser = conf.asObject(b);
if (!DeepEquals.deepEquals(toTest, deser)) {
throw new RuntimeException("oh no "+toTest);
}
}
示例8: fromByteArrayFst
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
/**
* Deserialize a byte array back to an object, with custom class loader.
*
* <p>
* This method uses FST lib.
* </p>
*
* @param data
* @param clazz
* @param classLoader
* @return
* @since 0.6.0
*/
@SuppressWarnings("unchecked")
public static <T> T fromByteArrayFst(final byte[] data, final Class<T> clazz,
final ClassLoader classLoader) {
if (data == null) {
return null;
}
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
if (classLoader != null) {
Thread.currentThread().setContextClassLoader(classLoader);
}
try {
FSTConfiguration conf = fstConf.get();
conf.setClassLoader(classLoader != null ? classLoader : oldClassLoader);
Object result = conf.asObject(data);
if (result != null && clazz.isAssignableFrom(result.getClass())) {
return (T) result;
} else {
return null;
}
} catch (Exception e) {
throw e instanceof DeserializationException ? (DeserializationException) e
: new DeserializationException(e);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
示例9: testLarge
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void testLarge() throws UnsupportedEncodingException {
FSTConfiguration js = FSTConfiguration.createJsonConfiguration();
byte[] bytes = getBytes(getTestJSON());
Unknown x = (Unknown) js.asObject(bytes);
System.out.println(x.dot(0,"_id"));
System.out.println(x.dot(1,"friends",1,"name"));
System.out.println(x);
}
示例10: testBigInt
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test @Ignore
// in case number and names of instance fields of reader/writer are different,
// this fails as code below implicitely assumes, fields of writer == fields of reader
// unfortunately one can use defaultWriteObject at writer side but use getFields at reader side
// in readObject(). if then fields differ, code below reads BS and fails.
// Its impossible to fix that except by always using putField + getField for
// JDK compatibility classes, however this will waste lots of performance. As
// it would be necessary to *always* write full metainformation (a map of fieldName => value pairs).
// Strategy will be to rely on custom serializers for now, as reading/writing a full hashmap for
// each defaultWriteObject/readObject is overkill. Additionally as JDK assumes defaultWriteObject is
// binary compatible to writeObject (which is trueish for fast-ser), the need to write hashmaps would
// transition/leak also to default serailization.
// see #53.
public void testBigInt() {
FSTConfiguration androidConf = FSTConfiguration.createAndroidDefaultConfiguration();
androidConf.registerClass(AndroidBigInt.class);
// some trickery to read bitset from androidbitset
FSTConfiguration jdkConf = FSTConfiguration.createAndroidDefaultConfiguration();
jdkConf.registerClass(JDKBigInt.class);
final AndroidBigInt abs = new AndroidBigInt(-4, new byte[] { 1,2,3,4,5,6,7 });
Object androidOriginal = new Object[] {abs,"dummy"};
byte androidSerialized[] = androidConf.asByteArray( androidOriginal );
Object read = jdkConf.asObject(androidSerialized);
byte reverse[] = jdkConf.asByteArray(read);
Object androidBS = androidConf.asObject(reverse);
assertTrue(DeepEquals.deepEquals(androidBS, androidOriginal));
}
示例11: shouldSerializeUnmodifiableList
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void shouldSerializeUnmodifiableList() throws ClassNotFoundException {
//given
List<String> list = Collections.unmodifiableList(Collections.singletonList(TEST_VALUE));
FSTConfiguration conf = FSTConfiguration.createJsonNoRefConfiguration();
//when
byte[] bytes = conf.asByteArray((list));
list = (List<String>) conf.asObject(bytes);
//then
assertTrue(FSTJSonUnmodifiableCollectionSerializer.UNMODIFIABLE_LIST_CLASS.isAssignableFrom(list.getClass()));
assertEquals(1, list.size());
assertTrue(list.contains(TEST_VALUE));
}
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:14,代码来源:FSTJSonUnmodifiableCollectionSerializerTest.java
示例12: shouldSerializeUnmodifiableSet
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void shouldSerializeUnmodifiableSet() throws ClassNotFoundException {
//given
Set<String> set = Collections.unmodifiableSet(Collections.singleton(TEST_VALUE));
FSTConfiguration conf = FSTConfiguration.createJsonNoRefConfiguration();
//when
byte[] bytes = conf.asByteArray((set));
set = (Set<String>) conf.asObject(bytes);
//then
assertTrue(FSTJSonUnmodifiableCollectionSerializer.UNMODIFIABLE_SET_CLASS.isAssignableFrom(set.getClass()));
assertEquals(1, set.size());
assertTrue(set.contains(TEST_VALUE));
}
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:14,代码来源:FSTJSonUnmodifiableCollectionSerializerTest.java
示例13: shouldSerializeUnmodifiableMap
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void shouldSerializeUnmodifiableMap() throws ClassNotFoundException {
//given
Map<String, String> map = Collections.unmodifiableMap(Collections.singletonMap(TEST_KEY, TEST_VALUE));
FSTConfiguration conf = FSTConfiguration.createJsonNoRefConfiguration();
//when
byte[] bytes = conf.asByteArray((map));
map = (Map<String, String>) conf.asObject(bytes);
//then
assertTrue(FSTJSonUnmodifiableMapSerializer.UNMODIFIABLE_MAP_CLASS.isAssignableFrom(map.getClass()));
assertEquals(1, map.size());
assertTrue(map.containsKey(TEST_KEY));
assertTrue(map.containsValue(TEST_VALUE));
}
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:15,代码来源:FSTJSonUnmodifiableMapSerializerTest.java
示例14: shouldSerializeEnumSet
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void shouldSerializeEnumSet() throws Exception {
FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
byte[] bytes = conf.asByteArray(new Clazz());
Clazz o = (Clazz) conf.asObject(bytes);
Assert.assertEquals(o.enumSet, EnumSet.of(SomeEnum.override, SomeEnum.plain));
}
示例15: testUnknown
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void testUnknown() throws UnsupportedEncodingException {
FSTConfiguration js = FSTConfiguration.createJsonConfiguration();
byte[] bytes = getBytes("{ 'asd' : 123, '123': 3345.32, 'pok': { 'pak': '345', 'pick':[1,2,3,4.5,[1,2,'3']] } }");
Unknown x = (Unknown) js.asObject(bytes);
String ddot = x.ddot("pok.pak");
System.out.println(ddot);
System.out.println(x);
}