當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。