Java 类java.io.Externalizable 实例源码

项目:gemini.blueprint    文件:OsgiReferenceCollectionNamespaceHandlerTest.java   
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);

}
项目:incubator-hivemall    文件:ObjectUtils.java   
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);
    }
}
项目:aidl2    文件:ExternalizableTest3$$AidlServerImpl.java   
@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);
}
项目:aidl2    文件:ExternalizableTest3$$AidlClientImpl.java   
@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();
    }
}
项目:javify    文件:CommandInfo.java   
/**
 * 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;
}
项目:jvm-stm    文件:CommandInfo.java   
/**
 * 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;
}
项目:hRouting_Android    文件:GraphSerializerUtil.java   
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;
}
项目:ignite    文件:BinaryUtils.java   
/**
 * 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;
}
项目:flex-blazeds    文件:Amf3Input.java   
/**
 *
 */
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;
    }
}
项目:riotapi    文件:Amf0ObjectDeserializer.java   
@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;
}
项目:JamVM-PH    文件:CommandInfo.java   
/**
 * 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;
}
项目:hRouting_Android    文件:GraphSerializerUtil.java   
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;
}
项目:spring-osgi    文件:OsgiReferenceCollectionNamespaceHandlerTest.java   
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);

}
项目:classpath    文件:CommandInfo.java   
/**
 * 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;
}
项目:fast-serialization    文件:FSTObjectInputNoShared.java   
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;
}
项目:swarm    文件:U_Serialization.java   
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);
        }
    }
}
项目:spliceengine    文件:SerializationUtils.java   
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;
    }
项目:oscm    文件:InterfaceMapTest.java   
@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));
}
项目:oscm    文件:InterfaceMap.java   
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);
}
项目:oscm    文件:InterfaceMapTest.java   
@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));
}
项目:gemini.blueprint    文件:OsgiReferenceNamespaceHandlerTest.java   
public void testMultipleInterfaces() throws Exception {
    OsgiServiceProxyFactoryBean factory = (OsgiServiceProxyFactoryBean) appContext.getBean("&multi-interfaces");
    Class<?>[] intfs = (Class[]) TestUtils.getFieldValue(factory, "interfaces");
    assertNotNull(intfs);
    assertEquals(2, intfs.length);

    assertTrue(Arrays.equals(new Class<?>[] { Serializable.class, Externalizable.class }, intfs));
}
项目:gemini.blueprint    文件:OsgiReferenceCollectionNamespaceHandlerTest.java   
public void testSimpleSortedSet() {
    Object factoryBean = appContext.getBean("&implicitSortedSet");
    assertTrue(factoryBean instanceof OsgiServiceCollectionProxyFactoryBean);

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

    Class<?>[] intfs = getInterfaces(factoryBean);
    assertTrue(Arrays.equals(new Class<?>[] { Externalizable.class }, intfs));
}
项目:gemini.blueprint    文件:OsgiReferenceCollectionNamespaceHandlerTest.java   
public void testSortedListWithNaturalOrderingOnServs() throws Exception {
    Object factoryBean = appContext.getBean("&sortedListWithNaturalOrderingOnServs");
    assertTrue(factoryBean instanceof OsgiServiceCollectionProxyFactoryBean);

    assertNull(getComparator(factoryBean));

    Object bean = appContext.getBean("sortedListWithNaturalOrderingOnServs");
    assertFalse(bean instanceof OsgiServiceSortedList);
    assertTrue(bean instanceof List);

    Class<?>[] intfs = getInterfaces(factoryBean);
    assertTrue(Arrays.equals(new Class<?>[] { Externalizable.class }, intfs));
}
项目:lams    文件:AbstractJsonWriter.java   
/**
 * Method to declare various Java types to be handles as JSON array.
 * 
 * @param clazz the type
 * @return <code>true</code> if handles as array
 * @since 1.4
 */
protected boolean isArray(final Class<?> clazz) {
    return clazz != null
        && (clazz.isArray()
            || Collection.class.isAssignableFrom(clazz)
            || Externalizable.class.isAssignableFrom(clazz)
            || Map.class.isAssignableFrom(clazz) || Map.Entry.class.isAssignableFrom(clazz));
}
项目:jdk8u-jdk    文件:ReflectionFactory.java   
/**
 * Returns an accessible no-arg constructor for an externalizable class to be
 * initialized using a public no-argument constructor.
 *
 * @param cl the class to instantiate
 * @return A no-arg constructor for the class; returns {@code null} if
 *     the class does not implement {@link java.io.Externalizable}
 */
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
    if (!Externalizable.class.isAssignableFrom(cl)) {
        return null;
    }
    try {
        Constructor<?> cons = cl.getConstructor();
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
项目:openjdk-jdk10    文件:ReflectionFactory.java   
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
    if (!Externalizable.class.isAssignableFrom(cl)) {
        return null;
    }
    try {
        Constructor<?> cons = cl.getConstructor();
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
项目:mimi-reader    文件:MimiUtil.java   
public static boolean writeObjectToFile(final File saveFile, final Externalizable data) {
        ObjectOutput out;
        try {
            out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(saveFile, true)));
            data.writeExternal(out);
//            out.writeObject(data);
            out.close();
        } catch (Exception e) {
            Log.e(LOG_TAG, "Error writing bookmark to file", e);
            return false;
        }

        return true;
    }
项目:gemfirexd-oss    文件:Marshaller.java   
/**
 * Writes an object to the ObjectOutput stream.
 * If possible, we will send over a magic number instead of the class name
 * so that we transfer less amount of data.
 * @param inst - an object instance to be serialized, can not be null
 * @param out - the ObjectOutput stream we will write the serialized data to
 */
public static void write(Externalizable inst, ObjectOutput out) throws IOException {
    boolean is_null=(inst == null);
    try {
        // if inst is a null value we write this first
        out.writeBoolean(is_null);
        if(is_null)
            return;

        //find out if we have a magic number for this class
        int magic=mConfigurator.getMagicNumber(inst.getClass());
        //-1 means no magic number otherwise we have one
        if(magic != -1) {
            //true means we use a magic number
            out.writeBoolean(true);
            //write the magic number
            out.writeInt(magic);
        }
        else {
            //we don't have a magic number
            out.writeBoolean(false);
            //write the classname instead
            out.writeUTF(inst.getClass().getName());
        }//end if
        //write the object data
        inst.writeExternal(out);
    }
    catch(Exception x) {
        if(x instanceof IOException)
            throw (IOException)x;
        else
            throw new java.io.IOException(x.toString());
    }
}
项目:jdk8u_jdk    文件:ReflectionFactory.java   
/**
 * Returns an accessible no-arg constructor for an externalizable class to be
 * initialized using a public no-argument constructor.
 *
 * @param cl the class to instantiate
 * @return A no-arg constructor for the class; returns {@code null} if
 *     the class does not implement {@link java.io.Externalizable}
 */
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
    if (!Externalizable.class.isAssignableFrom(cl)) {
        return null;
    }
    try {
        Constructor<?> cons = cl.getConstructor();
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:ReflectionFactory.java   
/**
 * Returns an accessible no-arg constructor for an externalizable class to be
 * initialized using a public no-argument constructor.
 *
 * @param cl the class to instantiate
 * @return A no-arg constructor for the class; returns {@code null} if
 *     the class does not implement {@link java.io.Externalizable}
 */
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
    if (!Externalizable.class.isAssignableFrom(cl)) {
        return null;
    }
    try {
        Constructor<?> cons = cl.getConstructor();
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
项目:incubator-hivemall    文件:ObjectUtils.java   
public static byte[] toCompressedBytes(@Nonnull final Externalizable obj) throws IOException {
    FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(bos);
    try {
        toStream(obj, dos);
        dos.finish();
        dos.flush();
        return bos.toByteArray_clear();
    } finally {
        IOUtils.closeQuietly(dos);
    }
}
项目:incubator-hivemall    文件:ObjectUtils.java   
public static void readCompressedObject(@Nonnull final byte[] src,
        @Nonnull final Externalizable dst) throws IOException, ClassNotFoundException {
    FastByteArrayInputStream bis = new FastByteArrayInputStream(src);
    final InflaterInputStream iis = new InflaterInputStream(bis);
    try {
        readObject(iis, dst);
    } finally {
        IOUtils.closeQuietly(iis);
    }
}
项目:incubator-hivemall    文件:ObjectUtils.java   
public static void readCompressedObject(@Nonnull final byte[] src, final int len,
        @Nonnull final Externalizable dst, @Nonnull final CompressionAlgorithm algo,
        final boolean bin2txt) throws IOException, ClassNotFoundException {
    FastByteArrayInputStream bis = new FastByteArrayInputStream(src, len);
    InputStream in = null;
    InputStream compressedStream = null;
    try {
        in = bin2txt ? new Base91InputStream(bis) : bis;
        compressedStream = CompressionStreamFactory.createInputStream(in, algo);
        readObject(compressedStream, dst);
    } finally {
        IOUtils.closeQuietly(compressedStream);
        IOUtils.closeQuietly(in);
    }
}
项目:incubator-hivemall    文件:ObjectUtils.java   
public static void readCompressedObject(@Nonnull final byte[] src, final int offset,
        final int length, @Nonnull final Externalizable dst) throws IOException,
        ClassNotFoundException {
    FastByteArrayInputStream bis = new FastByteArrayInputStream(src, offset, length);
    final InflaterInputStream iis = new InflaterInputStream(bis);
    try {
        readObject(iis, dst);
    } finally {
        IOUtils.closeQuietly(iis);
    }
}
项目:aidl2    文件:Writer.java   
public Writer(AidlProcessor.Environment environment, State state, CharSequence outParcelName) {
    super(environment);

    this.nullable = state.nullable;
    this.assumeFinal = state.assumeFinal;
    this.name = state.name;
    this.allocator = state.allocator;

    this.parcelName = outParcelName;

    this.allowUnchecked = state.allowUnchecked;

    this.sizeType = lookup("android.util.Size");
    this.sizeF = lookup("android.util.SizeF");
    this.parcelable = lookup("android.os.Parcelable");
    this.iBinder = lookup("android.os.IBinder");
    this.bundle = lookup("android.os.Bundle");
    this.persistable = lookup("android.os.PersistableBundle");
    this.sparseBoolArray = lookup("android.util.SparseBooleanArray");

    string = lookup(String.class);
    charSequence = lookup(CharSequence.class);

    this.serializable = lookup(Serializable.class);
    this.externalizable = lookup(Externalizable.class);

    this.theIterator = lookup(Iterator.class);

    collectionIterator = lookupMethod(theCollection, "iterator", "Iterator");
    mapEntrySet = lookupMethod(theMap, "entrySet", Set.class);

    if (state.returnValue) {
        flags = Util.literal("$T.PARCELABLE_WRITE_RETURN_VALUE", parcelable);
    } else {
        flags = 0;
    }
}
项目:aidl2    文件:ExternalizableTest2$$AidlServerImpl.java   
@Override
protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
    switch(code) {
        case TRANSACT_methodWithExternalizableReturn: {
            data.enforceInterface(this.getInterfaceDescriptor());

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

            if (returnValue == null) {
                reply.writeByte((byte) -1);
            } else {
                reply.writeByte((byte) 0);
                ObjectOutputStream objectOutputStream = null;
                try {
                    ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
                    objectOutputStream = new ObjectOutputStream(arrayOutputStream);
                    returnValue.writeExternal(objectOutputStream);
                    objectOutputStream.flush();
                    reply.writeByteArray(arrayOutputStream.toByteArray());
                } catch (Exception e) {
                    throw new IllegalStateException("Failed to serialize net.sf.aidl2.SomeExternalizable", e);
                } finally {
                    AidlUtil.shut(objectOutputStream);
                }
            }

            return true;
        }
    }
    return super.onTransact(code, data, reply, flags);
}
项目:javify    文件:ValueHandlerDelegateImpl.java   
/**
 * Compute the repository id in the RMI hashed format.
 */
public String getRMIRepositoryID(final Class cx)
{
  long hash = 0;
  Class of = cx.isArray() ? cx.getComponentType() : null;

  if (cx.equals(String[].class))
    return RMI_STRING_ARRAY_ID;
  else if (cx.equals(String.class))
    return RMI_STRING_ID;
  else if (cx.equals(Class.class))
    return RMI_CLASS_ID;
  else if (Remote.class.isAssignableFrom(cx)
    || !Serializable.class.isAssignableFrom(cx)
    || cx.isInterface()
    || (cx.isArray() && (!Serializable.class.isAssignableFrom(of)
      || of.isPrimitive() || Remote.class.isAssignableFrom(of)))

  )
    // Some classes that have zero hash code and serial no version id
    // included.
    return "RMI:" + cx.getName() + ":" + toHex(hash);
  else if (cx.isArray())
    // Arrays have the same hashcode and uid as they components.
    return "RMI:" + cx.getName() + ":" + toHex(getHashCode(of)) + ":"
      + toHex(getSid(of));
  else
    {
      if (Externalizable.class.isAssignableFrom(cx))
        hash = 1;
      else
        hash = getHashCode(cx);

      return "RMI:" + cx.getName() + ":" + toHex(hash) + ":"
        + toHex(getSid(cx));
    }
}
项目:development    文件:InterfaceMapTest.java   
@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));
}
项目:development    文件:InterfaceMap.java   
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);
}
项目:development    文件:InterfaceMapTest.java   
@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));
}