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


Java Externalizable类代码示例

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


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

示例1: getCommandObject

import java.io.Externalizable; //导入依赖的package包/类
/**
 * Returns the instantiated bean.
 * If the bean implements <code>CommandObject</code>, its
 * <code>setCommandContext</code> method will be called.
 * @param dh the data handler describing the command data
 * @param loader the class loader used to instantiate the bean
 */
public Object getCommandObject(DataHandler dh, ClassLoader loader)
  throws IOException, ClassNotFoundException
{
  Object object = Beans.instantiate(loader, className);
  if (object != null)
    {
      if (object instanceof CommandObject)
        {
          CommandObject command = (CommandObject)object;
          command.setCommandContext(verb, dh);
        }
      else if (dh != null && (object instanceof Externalizable))
        {
          InputStream in = dh.getInputStream();
          if (in != null)
            {
              Externalizable externalizable = (Externalizable)object;
              externalizable.readExternal(new ObjectInputStream(in));
            }
        }
    }
  return object;
}
 
开发者ID:vilie,项目名称:javify,代码行数:31,代码来源:CommandInfo.java

示例2: testSortedSetWithNaturalOrderingOnRefs

import java.io.Externalizable; //导入依赖的package包/类
public void testSortedSetWithNaturalOrderingOnRefs() throws Exception {
	Object factoryBean = appContext.getBean("&sortedSetWithNaturalOrderingOnRefs");
	assertTrue(factoryBean instanceof OsgiServiceCollectionProxyFactoryBean);

	Comparator comp = getComparator(factoryBean);

	assertNotNull(comp);
	assertSame(ServiceReferenceComparator.class, comp.getClass());

	Class<?>[] intfs = getInterfaces(factoryBean);
	assertTrue(Arrays.equals(new Class<?>[] { Externalizable.class }, intfs));

	OsgiServiceLifecycleListener[] listeners = getListeners(factoryBean);
	assertEquals(2, listeners.length);

	Object bean = appContext.getBean("sortedSetWithNaturalOrderingOnRefs");
	assertFalse(bean instanceof OsgiServiceSortedSet);
	assertTrue(bean instanceof SortedSet);

}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:21,代码来源:OsgiReferenceCollectionNamespaceHandlerTest.java

示例3: toCompressedBytes

import java.io.Externalizable; //导入依赖的package包/类
public static byte[] toCompressedBytes(@Nonnull final Externalizable obj,
        @Nonnull final CompressionAlgorithm algo, final boolean bin2txt) throws IOException {
    FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream();
    OutputStream out = null;
    FinishableOutputStream dos = null;
    try {
        out = bin2txt ? new Base91OutputStream(bos) : bos;
        dos = CompressionStreamFactory.createOutputStream(out, algo);
        toStream(obj, dos);
        dos.finish();
        //dos.flush();
        return bos.toByteArray_clear();
    } finally {
        IOUtils.closeQuietly(dos);
        IOUtils.closeQuietly(out);
    }
}
 
开发者ID:apache,项目名称:incubator-hivemall,代码行数:18,代码来源:ObjectUtils.java

示例4: onTransact

import java.io.Externalizable; //导入依赖的package包/类
@Override
protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
    switch(code) {
        case TRANSACT_methodReturningTheExternalizable: {
            data.enforceInterface(this.getInterfaceDescriptor());

            final Externalizable returnValue = delegate.methodReturningTheExternalizable();
            reply.writeNoException();

            AidlUtil.writeToObjectStream(reply, returnValue);

            return true;
        }
    }
    return super.onTransact(code, data, reply, flags);
}
 
开发者ID:chdir,项目名称:aidl2,代码行数:17,代码来源:ExternalizableTest3$$AidlServerImpl.java

示例5: methodReturningTheExternalizable

import java.io.Externalizable; //导入依赖的package包/类
@Override
public Externalizable methodReturningTheExternalizable() throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(ExternalizableTest3$$AidlServerImpl.DESCRIPTOR);

        delegate.transact(ExternalizableTest3$$AidlServerImpl.TRANSACT_methodReturningTheExternalizable, data, reply, 0);
        reply.readException();

        return AidlUtil.readFromObjectStream(reply);
    } finally {
        data.recycle();
        reply.recycle();
    }
}
 
开发者ID:chdir,项目名称:aidl2,代码行数:17,代码来源:ExternalizableTest3$$AidlClientImpl.java

示例6: deSerialize

import java.io.Externalizable; //导入依赖的package包/类
public static Graph deSerialize(byte[] byteArray,
                                Class<? extends Externalizable> clazz) {
    ObjectInputStream ois;
    Graph graph;
    try {
        ois = new ObjectInputStream(new ByteArrayInputStream(byteArray));
        graph = (Graph) clazz.newInstance();
        graph.readExternal(ois);
        ois.close();
    } catch (IOException | ClassNotFoundException | InstantiationException
            | IllegalAccessException e) {
        e.printStackTrace();
        return null;
    }
    Preconditions.checkNotNull(graph);
    return graph;
}
 
开发者ID:dhasenfratz,项目名称:hRouting_Android,代码行数:18,代码来源:GraphSerializerUtil.java

示例7: isCustomJavaSerialization

import java.io.Externalizable; //导入依赖的package包/类
/**
 * Determines whether class contains custom Java serialization logic.
 *
 * @param cls Class.
 * @return {@code true} if custom Java serialization logic exists, {@code false} otherwise.
 */
@SuppressWarnings("unchecked")
public static boolean isCustomJavaSerialization(Class cls) {
    for (Class c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
        if (Externalizable.class.isAssignableFrom(c))
            return true;

        try {
            Method writeObj = c.getDeclaredMethod("writeObject", ObjectOutputStream.class);
            Method readObj = c.getDeclaredMethod("readObject", ObjectInputStream.class);

            if (!Modifier.isStatic(writeObj.getModifiers()) && !Modifier.isStatic(readObj.getModifiers()) &&
                writeObj.getReturnType() == void.class && readObj.getReturnType() == void.class)
                return true;
        }
        catch (NoSuchMethodException ignored) {
            // No-op.
        }
    }

    return false;
}
 
开发者ID:apache,项目名称:ignite,代码行数:28,代码来源:BinaryUtils.java

示例8: readExternalizable

import java.io.Externalizable; //导入依赖的package包/类
/**
 *
 */
protected void readExternalizable(String className, Object object) throws ClassNotFoundException, IOException
{
    if (object instanceof Externalizable)
    {
        if (isDebug)
            trace.startExternalizableObject(className, objectTable.size() - 1);

        ((Externalizable)object).readExternal(this);
    }
    else
    {
        //Class '{className}' must implement java.io.Externalizable to receive client IExternalizable instances.
        SerializationException ex = new SerializationException();
        ex.setMessage(10305, new Object[] {object.getClass().getName()});
        throw ex;
    }
}
 
开发者ID:apache,项目名称:flex-blazeds,代码行数:21,代码来源:Amf3Input.java

示例9: deserialize

import java.io.Externalizable; //导入依赖的package包/类
@SneakyThrows
public Object deserialize(AmfReader reader) {
    Object result = cls.newInstance();

    if (result instanceof Externalizable) {
        ((Externalizable) result).readExternal(reader);
        return result;
    }


    for (Map.Entry<String, Object> field : reader.readAmf0KeyValuePairs().entrySet()) {
        setField(result, field.getKey(), field.getValue());
    }

    return result;
}
 
开发者ID:loldevs,项目名称:riotapi,代码行数:17,代码来源:Amf0ObjectDeserializer.java

示例10: testSortedSetWithNaturalOrderingOnRefs

import java.io.Externalizable; //导入依赖的package包/类
public void testSortedSetWithNaturalOrderingOnRefs() throws Exception {
	Object factoryBean = appContext.getBean("&sortedSetWithNaturalOrderingOnRefs");
	assertTrue(factoryBean instanceof OsgiServiceCollectionProxyFactoryBean);

	Comparator comp = getComparator(factoryBean);

	assertNotNull(comp);
	assertSame(ServiceReferenceComparator.class, comp.getClass());

	Class[] intfs = getInterfaces(factoryBean);
	assertTrue(Arrays.equals(new Class[] { Externalizable.class }, intfs));

	OsgiServiceLifecycleListener[] listeners = getListeners(factoryBean);
	assertEquals(2, listeners.length);

	Object bean = appContext.getBean("sortedSetWithNaturalOrderingOnRefs");
	assertFalse(bean instanceof OsgiServiceSortedSet);
	assertTrue(bean instanceof SortedSet);

}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:21,代码来源:OsgiReferenceCollectionNamespaceHandlerTest.java

示例11: instantiateAndReadNoSer

import java.io.Externalizable; //导入依赖的package包/类
protected Object instantiateAndReadNoSer(Class c, FSTClazzInfo clzSerInfo, FSTClazzInfo.FSTFieldInfo referencee, int readPos) throws Exception {
    Object newObj;
    newObj = clzSerInfo.newInstance(getCodec().isMapBased());
    if (newObj == null) {
        throw new IOException(referencee.getDesc() + ":Failed to instantiate '" + c.getName() + "'. Register a custom serializer implementing instantiate or define empty constructor..");
    }
    if ( clzSerInfo.isExternalizable() )
    {
        getCodec().ensureReadAhead(readExternalReadAHead);
        ((Externalizable)newObj).readExternal(this);
        getCodec().readExternalEnd();
    } else {
        FSTClazzInfo.FSTFieldInfo[] fieldInfo = clzSerInfo.getFieldInfo();
        readObjectFields(referencee, clzSerInfo, fieldInfo, newObj,0,0);
    }
    return newObj;
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:18,代码来源:FSTObjectInputNoShared.java

示例12: writeNullableObject

import java.io.Externalizable; //导入依赖的package包/类
public static void writeNullableObject(Serializable object, ObjectOutput out) throws IOException
{
	boolean isNull = object == null;
	out.writeBoolean(isNull);
	
	if( !isNull )
	{
		if( object instanceof Externalizable )
		{
			((Externalizable)object).writeExternal(out);
		}
		else
		{
			out.writeObject(object);
		}
	}
}
 
开发者ID:dougkoellmer,项目名称:swarm,代码行数:18,代码来源:U_Serialization.java

示例13: serializeToBytes

import java.io.Externalizable; //导入依赖的package包/类
public static byte[] serializeToBytes(Externalizable e) throws IOException {

        ByteArrayOutputStream bos = null;
        ObjectOutputStream oos = null;
        byte[] object;

        try{
            bos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(bos);
            oos.writeObject(e);
            oos.flush();

            object = bos.toByteArray();
        } finally {
            if(oos != null){
                oos.close();
            }

            if(bos != null){
                bos.close();
            }
        }

        return object;
    }
 
开发者ID:splicemachine,项目名称:spliceengine,代码行数:26,代码来源:SerializationUtils.java

示例14: testGet

import java.io.Externalizable; //导入依赖的package包/类
@Test
public void testGet() {
    InterfaceMap<Object> map = new InterfaceMap<Object>();
    A a = new A();
    B b = new B();
    map.put(a, a);
    map.put(b, b);
    assertSame(a, map.get(Runnable.class));
    assertSame(b, map.get(Externalizable.class));
    assertSame(b, map.get(Comparable.class));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:InterfaceMapTest.java

示例15: isExcplicitlyRequiredClass

import java.io.Externalizable; //导入依赖的package包/类
private boolean isExcplicitlyRequiredClass(Class<?> i) {
    Set<Class<?>> requiredClasses = new HashSet<Class<?>>();
    requiredClasses.add(EJBTestBase.Caller.class);
    requiredClasses.add(Comparable.class);
    requiredClasses.add(Runnable.class);
    requiredClasses.add(Externalizable.class);
    requiredClasses.add(javax.enterprise.event.Event.class);
    requiredClasses.add(org.slf4j.Logger.class);
    return requiredClasses.contains(i);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:11,代码来源:InterfaceMap.java


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