当前位置: 首页>>代码示例>>Java>>正文


Java FSTConfiguration.asByteArray方法代码示例

本文整理汇总了Java中org.nustaq.serialization.FSTConfiguration.asByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java FSTConfiguration.asByteArray方法的具体用法?Java FSTConfiguration.asByteArray怎么用?Java FSTConfiguration.asByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.nustaq.serialization.FSTConfiguration的用法示例。


在下文中一共展示了FSTConfiguration.asByteArray方法的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);
}
 
开发者ID:chuidiang,项目名称:chuidiang-ejemplos,代码行数:20,代码来源:FstExample.java

示例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);
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:20,代码来源:I52.java

示例3: testBitSet

import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void testBitSet() {
    FSTConfiguration androidConf = FSTConfiguration.createAndroidDefaultConfiguration();
    androidConf.registerClass(AndroidBItSet.class);

    // some trickery to read bitset from androidbitset
    FSTConfiguration jdkConf = FSTConfiguration.createAndroidDefaultConfiguration();
    jdkConf.registerClass(JDKBitSet.class);


    final AndroidBItSet abs = new AndroidBItSet(777);
    Object androidOriginal = new Object[] {abs,"dummy"};
    abs.set(666, 700, true);
    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));
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:23,代码来源:AndroidBitSetTest.java

示例4: toByteArrayFst

import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
/**
 * Serialize an object to byte array, with a custom class loader.
 * 
 * <p>
 * This method uses FST lib.
 * </p>
 * 
 * @param obj
 * @param classLoader
 * @return
 * @since 0.6.0
 */
public static byte[] toByteArrayFst(final Object obj, final ClassLoader classLoader) {
    if (obj == 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);
        return conf.asByteArray(obj);
    } catch (Exception e) {
        throw e instanceof SerializationException ? (SerializationException) e
                : new SerializationException(e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
 
开发者ID:DDTH,项目名称:ddth-commons,代码行数:32,代码来源:SerializationUtils.java

示例5: 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);
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:11,代码来源:Git67.java

示例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());
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:38,代码来源:TestFastSerialization.java

示例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);
    }
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:8,代码来源:SpecialsTest.java

示例8: 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));
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:34,代码来源:AndroidBitSetTest.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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));
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:8,代码来源:FSTEnumSetSerializerTest.java

示例13: shouldCompatibleSerializeEnumSet

import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void shouldCompatibleSerializeEnumSet() throws Exception {
    FSTConfiguration conf = FSTConfiguration.createMinBinConfiguration();
    byte[] bytes = conf.asByteArray(new Clazz());
    Clazz o = (Clazz) conf.asObject(bytes);
    Assert.assertEquals(o.enumSet, EnumSet.of(SomeEnum.override, SomeEnum.plain));
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:8,代码来源:FSTEnumSetSerializerTest.java

示例14: shouldCompatibleSerializeEmptyEnumSet

import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void shouldCompatibleSerializeEmptyEnumSet() throws Exception {
    FSTConfiguration conf = FSTConfiguration.createMinBinConfiguration();
    Clazz object = new Clazz();
    object.enumSet = EnumSet.noneOf(SomeEnum.class);
    byte[] bytes = conf.asByteArray(object);
    Clazz o = (Clazz) conf.asObject(bytes);
    Assert.assertEquals(o.enumSet, EnumSet.noneOf(SomeEnum.class));
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:10,代码来源:FSTEnumSetSerializerTest.java

示例15: asByte

import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
public static byte[] asByte(Object obj) {
  FSTConfiguration fst = getFST();
  return fst.asByteArray(obj);
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:5,代码来源:Serializer.java


注:本文中的org.nustaq.serialization.FSTConfiguration.asByteArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。