本文整理汇总了Java中org.nustaq.serialization.FSTConfiguration.createDefaultConfiguration方法的典型用法代码示例。如果您正苦于以下问题:Java FSTConfiguration.createDefaultConfiguration方法的具体用法?Java FSTConfiguration.createDefaultConfiguration怎么用?Java FSTConfiguration.createDefaultConfiguration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.nustaq.serialization.FSTConfiguration
的用法示例。
在下文中一共展示了FSTConfiguration.createDefaultConfiguration方法的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;
}
示例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;
}
示例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);
}
示例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));
}
示例5: 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();
}
示例6: 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();
}
示例7: 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);
}
示例8: 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));
}
示例9: 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);
}
示例10: 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);
}
示例11: FileAccessor
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
/**
* Constructs a FileAccessor object with the default file path to store contents on disk
*/
public FileAccessor()
{
memoryPath = DEFAULT_MEMORY_FILE_PATH;
memoryExtension = DEFAULT_MEMORY_FILE_EXTENSION;
memoryFolder = new File(memoryPath);
try
{
if(!memoryFolder.exists())
{
memoryFolder.mkdir();
}
memoryInstance = findMemoryInstance();
}
catch(Exception e)
{
e.printStackTrace();
System.exit(-1);
}
if(fstConfiguration == null)
{
fstConfiguration = FSTConfiguration.createDefaultConfiguration();
}
}
示例12: initFST
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
/**
* Initializes the delegate serializer
*/
private void initFST() {
fastSerialConfig = FSTConfiguration.createDefaultConfiguration();
if(classes != null) {
fastSerialConfig.registerClass(classes);
}
}
示例13: 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);
}
示例14: FSTSerializer
import org.nustaq.serialization.FSTConfiguration; //导入方法依赖的package包/类
/**
* Create a FST serializer (faster and more efficient than Java default serialization).
*
* @param useUnsafe <code>true</code> to use <code>sun.misc.Unsafe</code> class, otherwise, a fallback is
* used.
* @param securityProvider the security provider, needed to decode key pairs correctly
*/
public FSTSerializer(boolean useUnsafe, ISecurityClassProvider securityProvider) {
if (!useUnsafe) {
// don't use sun.misc.Unsafe class
FSTUtil.unFlaggedUnsafe = null;
logger.debug("Disabled the use of 'sun.misc.Unsafe' for the serialization");
}
fst = FSTConfiguration.createDefaultConfiguration();
// register all often serialized classes for speedup. Note that every peer should have the same
// configuration, which also depends on the order! Changing these registrations might break backward
// compatibility!
fst.registerClass(UserProfile.class, FolderIndex.class, FileIndex.class, UserPermission.class, Locations.class,
UserPublicKey.class, MetaFileSmall.class, MetaFileLarge.class, FileVersion.class, MetaChunk.class,
Chunk.class, EncryptedNetworkContent.class, ContactPeerMessage.class, ResponseMessage.class);
// for all public / private keys for full compatibility among multiple security providers
fst.registerClass(securityProvider.getRSAPublicKeyClass(), securityProvider.getRSAPrivateKeyClass(),
securityProvider.getRSAPrivateCrtKeyClass());
// for performance improvements, native TomP2P classes which are serialized quite often
fst.registerClass(PeerAddress.class, PeerSocketAddress.class, Number160.class);
// Since PeerAddresses are serialized very often, this is just an efficiency improvement
fst.registerSerializer(PeerAddress.class, new FSTPeerAddressSerializer(), false);
// register the acceptance reply enum
fst.registerClass(AcceptanceReply.class);
}
示例15: 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]));
}