本文整理汇总了Java中org.nustaq.serialization.FSTConfiguration.getObjectOutput方法的典型用法代码示例。如果您正苦于以下问题:Java FSTConfiguration.getObjectOutput方法的具体用法?Java FSTConfiguration.getObjectOutput怎么用?Java FSTConfiguration.getObjectOutput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.nustaq.serialization.FSTConfiguration
的用法示例。
在下文中一共展示了FSTConfiguration.getObjectOutput方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: 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();
}
示例3: 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));
}
示例4: testCustomSerializer
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
@Test
public void testCustomSerializer() throws Exception {
FSTConfiguration FST = FSTConfiguration.createDefaultConfiguration();
//FST.setForceSerializable(true);
FST.registerSerializer(Bug34.NonSerializableClass.class, new Serializer(), false);
FSTObjectOutput out = FST.getObjectOutput();
out.writeObject(new Bug34.NonSerializableClass());
FSTObjectInput in = FST.getObjectInput(out.getCopyOfWrittenBuffer());
assertEquals(NonSerializableClass.class, in.readObject().getClass());
}
示例5: 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);
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());
}
示例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);
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());
}