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


Java FSTObjectOutput.getCopyOfWrittenBuffer方法代码示例

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


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

示例1: main

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的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

示例2: testHM

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的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

示例3: serializationTest

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的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);
	Set<ExternalizableTestClass> set = new HashSet<ExternalizableTestClass>();
	set.add(object);
	BeanTestClass2 bean = new BeanTestClass2(object, set);

	// when serialized and deserialized, the integer value of all ExternalizableTestClass objects 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(bean);
		data1 = bos.toByteArray();
	}

	// 2. deserialize
	BeanTestClass2 bean1;
	try (ByteArrayInputStream bis = new ByteArrayInputStream(data1); ObjectInput in = new ObjectInputStream(bis)) {
		bean1 = (BeanTestClass2) in.readObject();
	}

	Assert.assertEquals(1, bean1.getObject().getInteger());
	Assert.assertEquals(1, ((ExternalizableTestClass) bean1.getSet().toArray()[0]).getInteger());

	// FST
	// 1. serialize
	FSTConfiguration config = FSTConfiguration.createDefaultConfiguration();
	FSTObjectOutput out2 = config.getObjectOutput();
	out2.writeObject(bean);
	byte[] data2 = out2.getCopyOfWrittenBuffer();
	out2.close();

	// 2. deserialize
	BeanTestClass2 bean2 = (BeanTestClass2) config.getObjectInput(data2).readObject();
	
	Assert.assertEquals(1, bean2.getObject().getInteger());
	Assert.assertEquals(1, ((ExternalizableTestClass) bean2.getSet().toArray()[0]).getInteger());
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:45,代码来源:TestFastSerializationBean2.java

示例4: serializationTest

import org.nustaq.serialization.FSTObjectOutput; //导入方法依赖的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);
	BeanTestClass1 bean = new BeanTestClass1(object, object);

	// when serialized and deserialized, the integer value of all ExternalizableTestClass objects 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(bean);
		data1 = bos.toByteArray();
	}

	// 2. deserialize
	BeanTestClass1 bean1;
	try (ByteArrayInputStream bis = new ByteArrayInputStream(data1); ObjectInput in = new ObjectInputStream(bis)) {
		bean1 = (BeanTestClass1) in.readObject();
	}

	Assert.assertEquals(1, bean1.getObject1().getInteger());
	Assert.assertEquals(1, bean1.getObject2().getInteger());

	// FST
	// 1. serialize
	FSTConfiguration config = FSTConfiguration.createDefaultConfiguration();
	FSTObjectOutput out2 = config.getObjectOutput();
	out2.writeObject(bean);
	byte[] data2 = out2.getCopyOfWrittenBuffer();
	out2.close();

	// 2. deserialize
	BeanTestClass1 bean2 = (BeanTestClass1) config.getObjectInput(data2).readObject();
	
	Assert.assertEquals(1, bean2.getObject1().getInteger());
	Assert.assertEquals(1, bean2.getObject2().getInteger());
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:43,代码来源:TestFastSerializationBean1.java


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