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


Java FSTConfiguration类代码示例

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


FSTConfiguration类属于org.nustaq.serialization包,在下文中一共展示了FSTConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFSTConfiguration

import org.nustaq.serialization.FSTConfiguration; //导入依赖的package包/类
public static FSTConfiguration createFSTConfiguration() {
	final FSTConfiguration result = FSTConfiguration.createDefaultConfiguration();
	result.registerClass(Landscape.class);
	result.registerClass(System.class);
	result.registerClass(NodeGroup.class);
	result.registerClass(Node.class);
	result.registerClass(Communication.class);
	result.registerClass(CommunicationTileAccumulator.class);
	result.registerClass(CommunicationAccumulator.class);
	result.registerClass(Application.class);
	result.registerClass(ELanguage.class);
	result.registerClass(Component.class);
	result.registerClass(Clazz.class);
	result.registerClass(RuntimeInformation.class);
	result.registerClass(DatabaseQuery.class);
	result.registerClass(CommunicationClazz.class);
	result.registerClass(Point.class);

	return result;
}
 
开发者ID:ExplorViz,项目名称:explorviz-backend,代码行数:21,代码来源:RepositoryStorage.java

示例2: getFST

import org.nustaq.serialization.FSTConfiguration; //导入依赖的package包/类
public static FSTConfiguration getFST() {
  if (fst != null) {
    return fst;
  }
  FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
  conf.registerClass(
      Project.class,
      ProjectDependency.class,
      GradleProject.class,
      MavenProject.class,
      MeghanadaProject.class,
      ParameterName.class,
      MethodParameterNames.class,
      Scope.class,
      LineRange.class,
      Position.class,
      Variable.class,
      Range.class,
      Source.class,
      MethodParameter.class,
      ClassIndex.class,
      MemberDescriptor.class);
  fst = conf;
  return fst;
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:26,代码来源:Serializer.java

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

示例4: main

import org.nustaq.serialization.FSTConfiguration; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    FSTConfiguration config = FSTConfiguration.createDefaultConfiguration();
    FSTObjectOutput out = config.getObjectOutput();
    out.writeObject("foobar");
    byte[] savedBuffer = out.getCopyOfWrittenBuffer();
    byte[] reallySavedBuffer = Arrays.copyOf(savedBuffer, savedBuffer.length);

    System.out.println(Arrays.equals(savedBuffer, reallySavedBuffer));

    out.resetForReUse();
    out.writeObject("blah");
    byte[] secondBuffer = out.getCopyOfWrittenBuffer();

    System.out.println(Arrays.equals(savedBuffer, reallySavedBuffer));

    config.getObjectInput(savedBuffer);
    config.getObjectInputCopyFrom(secondBuffer, 0, secondBuffer.length);
    System.out.println(Arrays.equals(savedBuffer, reallySavedBuffer));
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:20,代码来源:Issue91.java

示例5: encodeDecode

import org.nustaq.serialization.FSTConfiguration; //导入依赖的package包/类
private static void encodeDecode(Object object) throws Exception {
    try {
        FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
        conf.setShareReferences(false);
        try (FSTObjectInput input = new FSTObjectInputNoShared(conf);
                FSTObjectOutput output = new FSTObjectOutputNoShared(conf)) {

            output.writeObject(object);
            byte[] bytes = output.getCopyOfWrittenBuffer();

            input.resetForReuseUseArray(bytes);
            Object read = input.readObject();

            System.out.println(read);
            System.out.println(object.equals(read));
        }
    } catch (Throwable e) {
        System.err.println(e.getClass() + ": " + e.getMessage());
    }
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:21,代码来源:GitHub159.java

示例6: testStreamReuse

import org.nustaq.serialization.FSTConfiguration; //导入依赖的package包/类
@Test
public void testStreamReuse() throws Exception {
    FSTConfiguration configuration = FSTConfiguration.createDefaultConfiguration();

    String expected = "Hello, World!";
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    FSTObjectOutput fstObjectOutput = configuration.getObjectOutput(baos);
    try {
        fstObjectOutput.writeObject(expected);
    } finally {
        fstObjectOutput.flush();
    }
    byte[] serializedData = baos.toByteArray();
    FSTObjectInput input = configuration.getObjectInput(new ByteArrayInputStream(serializedData));
    Object read = input.readObject();
    Assert.assertEquals(expected, read);

    FSTObjectInput secondInput = configuration.getObjectInput(new ByteArrayInputStream(new byte[0]));
    expectedException.expect(IOException.class);
    expectedException.expectMessage("Failed to read");
    secondInput.readObject();
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:23,代码来源:BasicReuseTest.java

示例7: test

import org.nustaq.serialization.FSTConfiguration; //导入依赖的package包/类
@Test
@Ignore
public void test() throws Throwable {
    FSTConfiguration fc = FSTConfiguration.createDefaultConfiguration();

    byte[] b;
    int len;
    try (FSTObjectOutput foo = new FSTObjectOutput(fc)) {
        foo.writeObject(new Outer());
        b = foo.getBuffer();
        len = foo.getWritten();
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(b, 0, len);
    FSTObjectInput foi = fc.getObjectInput(bais);
    foi.readObject();
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:17,代码来源:OverflowTest.java

示例8: testReadResolve

import org.nustaq.serialization.FSTConfiguration; //导入依赖的package包/类
@Test
public void testReadResolve() throws Exception {
    FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();

    Holder holder = new Holder();
    holder.o = new ToRead("foo");
    holder.o2 = holder.o;

    byte[] b = null;
    FSTObjectOutput out = new FSTObjectOutput(conf);
    out.writeObject(holder);
    out.flush();
    b = out.getBuffer();

    FSTObjectInput in = new FSTObjectInput(conf);
    in.resetForReuseUseArray(b,b.length);
    Object res = in.readObject();

    checkEquals(Holder.class, res.getClass());
    checkEquals(String.class, ((Holder) res).o.getClass());
    checkEquals("foo", ((Holder) res).o);

    checkEquals(String.class, ((Holder) res).o2.getClass());
    checkEquals("foo", ((Holder) res).o2);
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:26,代码来源:ReadResolve.java

示例9: testHM

import org.nustaq.serialization.FSTConfiguration; //导入依赖的package包/类
@Test
public void testHM() throws IOException, ClassNotFoundException {
    FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
    HashMap hm = createHM();
    HashMap hm1 = createHM1(hm);
    FSTObjectOutput oo = conf.getObjectOutput();
    oo.writeObject(hm);
    oo.writeObject(hm1);
    byte[] copyOfWrittenBuffer = oo.getCopyOfWrittenBuffer();

    FSTObjectInput in = conf.getObjectInput(copyOfWrittenBuffer);
    Object o1 = in.readObject();
    Object o2 = in.readObject();
    Assert.assertTrue(DeepEquals.deepEquals(o1,hm));
    Assert.assertTrue(DeepEquals.deepEquals(o2,hm1));
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:17,代码来源:BigObjTest.java

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

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

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

示例13: main

import org.nustaq.serialization.FSTConfiguration; //导入依赖的package包/类
public static void main( String arg[] ) {
    System.setProperty("fst.unsafe","true");
    Unsafe un = FSTUtil.getUnsafe();
    FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
    FSTClazzInfo cl = conf.getClassInfo(Sample.class);
    Sample test = new Sample();
    System.out.println("fioff "+cl.getFieldInfo("fastTime",Date.class).getMemOffset() );
    System.out.println("fioff "+cl.getFieldInfo("x",Sample.class).getMemOffset() );

    test.x = 9999;

    Sample other = new Sample();

    long pos = cl.getFieldInfo("x", Sample.class).getMemOffset();
    long siz = cl.getFieldInfo("s", Sample.class).getMemOffset()+8;
    byte b[] = new byte[(int) siz];
    un.copyMemory(test,0, b, 0, siz);

    other = copyObj(un,test, (int) siz);

}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:22,代码来源:AnotherOffheapThingy.java

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

示例15: createCodec

import org.nustaq.serialization.FSTConfiguration; //导入依赖的package包/类
@Override
public Codec<T> createCodec() {
    Class<?>[] preRegister;

    if (knownTypes == null || knownTypes.isEmpty()) {
        preRegister = null;
    } else {
        preRegister = new TreeMap<>(knownTypes).values().toArray(new Class[knownTypes.size()]);
    }

    FSTConfiguration cfg;

    if (useUnsafe) {
        cfg = FSTConfiguration.createUnsafeBinaryConfiguration();
    } else {
        cfg = FSTConfiguration.createDefaultConfiguration();
    }

    if (preRegister != null) {
        for (Class<?> type : preRegister) {
            cfg.registerClass(type);
        }
    }

    if (sharedReferences != null) {
        cfg.setShareReferences(sharedReferences);
    }

    return newCodec(cfg);
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:31,代码来源:FstCodecFactory.java


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