Java Code Examples for java.io.Externalizable

The following are top voted examples for showing how to use java.io.Externalizable. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: gemini.blueprint   File: OsgiReferenceCollectionNamespaceHandlerTest.java   View source code 6 votes vote down vote up
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);

}
 
Example 2
Project: incubator-hivemall   File: ObjectUtils.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 3
Project: aidl2   File: ExternalizableTest3$$AidlServerImpl.java   View source code 6 votes vote down vote up
@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);
}
 
Example 4
Project: aidl2   File: ExternalizableTest3$$AidlClientImpl.java   View source code 6 votes vote down vote up
@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();
    }
}
 
Example 5
Project: javify   File: CommandInfo.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
Project: jvm-stm   File: CommandInfo.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 7
Project: hRouting_Android   File: GraphSerializerUtil.java   View source code 6 votes vote down vote up
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;
}
 
Example 8
Project: ignite   File: BinaryUtils.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 9
Project: flex-blazeds   File: Amf3Input.java   View source code 6 votes vote down vote up
/**
 *
 */
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;
    }
}
 
Example 10
Project: riotapi   File: Amf0ObjectDeserializer.java   View source code 6 votes vote down vote up
@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;
}
 
Example 11
Project: JamVM-PH   File: CommandInfo.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 12
Project: hRouting_Android   File: GraphSerializerUtil.java   View source code 6 votes vote down vote up
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;
}
 
Example 13
Project: spring-osgi   File: OsgiReferenceCollectionNamespaceHandlerTest.java   View source code 6 votes vote down vote up
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);

}
 
Example 14
Project: classpath   File: CommandInfo.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 15
Project: fast-serialization   File: FSTObjectInputNoShared.java   View source code 6 votes vote down vote up
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;
}
 
Example 16
Project: swarm   File: U_Serialization.java   View source code 6 votes vote down vote up
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);
		}
	}
}
 
Example 17
Project: spliceengine   File: SerializationUtils.java   View source code 6 votes vote down vote up
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;
    }
 
Example 18
Project: oscm   File: InterfaceMapTest.java   View source code 5 votes vote down vote up
@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));
}
 
Example 19
Project: oscm   File: InterfaceMap.java   View source code 5 votes vote down vote up
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);
}
 
Example 20
Project: oscm   File: InterfaceMapTest.java   View source code 5 votes vote down vote up
@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));
}
 
Example 21
Project: gemini.blueprint   File: OsgiReferenceNamespaceHandlerTest.java   View source code 5 votes vote down vote up
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));
}
 
Example 22
Project: gemini.blueprint   File: OsgiReferenceCollectionNamespaceHandlerTest.java   View source code 5 votes vote down vote up
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));
}
 
Example 23
Project: gemini.blueprint   File: OsgiReferenceCollectionNamespaceHandlerTest.java   View source code 5 votes vote down vote up
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));
}
 
Example 24
Project: lams   File: AbstractJsonWriter.java   View source code 5 votes vote down vote up
/**
 * 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));
}
 
Example 25
Project: jdk8u-jdk   File: ReflectionFactory.java   View source code 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 26
Project: openjdk-jdk10   File: ReflectionFactory.java   View source code 5 votes vote down vote up
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;
    }
}
 
Example 27
Project: mimi-reader   File: MimiUtil.java   View source code 5 votes vote down vote up
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;
    }
 
Example 28
Project: gemfirexd-oss   File: Marshaller.java   View source code 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example 29
Project: jdk8u_jdk   File: ReflectionFactory.java   View source code 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 30
Project: lookaside_java-1.8.0-openjdk   File: ReflectionFactory.java   View source code 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 31
Project: incubator-hivemall   File: ObjectUtils.java   View source code 5 votes vote down vote up
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);
    }
}
 
Example 32
Project: incubator-hivemall   File: ObjectUtils.java   View source code 5 votes vote down vote up
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);
    }
}
 
Example 33
Project: incubator-hivemall   File: ObjectUtils.java   View source code 5 votes vote down vote up
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);
    }
}
 
Example 34
Project: incubator-hivemall   File: ObjectUtils.java   View source code 5 votes vote down vote up
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);
    }
}
 
Example 35
Project: aidl2   File: Writer.java   View source code 5 votes vote down vote up
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;
    }
}
 
Example 36
Project: aidl2   File: ExternalizableTest2$$AidlServerImpl.java   View source code 5 votes vote down vote up
@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);
}
 
Example 37
Project: javify   File: ValueHandlerDelegateImpl.java   View source code 5 votes vote down vote up
/**
 * 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));
    }
}
 
Example 38
Project: development   File: InterfaceMapTest.java   View source code 5 votes vote down vote up
@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));
}
 
Example 39
Project: development   File: InterfaceMap.java   View source code 5 votes vote down vote up
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);
}
 
Example 40
Project: development   File: InterfaceMapTest.java   View source code 5 votes vote down vote up
@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));
}