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


Java Externalizable.writeExternal方法代码示例

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


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

示例1: writeObjectToFile

import java.io.Externalizable; //导入方法依赖的package包/类
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;
    }
 
开发者ID:MimiReader,项目名称:mimi-reader,代码行数:15,代码来源:MimiUtil.java

示例2: write

import java.io.Externalizable; //导入方法依赖的package包/类
/**
 * 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());
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:41,代码来源:Marshaller.java

示例3: onTransact

import java.io.Externalizable; //导入方法依赖的package包/类
@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);
}
 
开发者ID:chdir,项目名称:aidl2,代码行数:33,代码来源:ExternalizableTest2$$AidlServerImpl.java

示例4: writeExternalizableList

import java.io.Externalizable; //导入方法依赖的package包/类
public static void writeExternalizableList(final List<Externalizable> list, final ObjectOutput out)
        throws IOException {

   if (list == null) {
      out.writeInt(-1);
   } else {
      final int listSize = list.size();
      out.writeInt(listSize);
      for (final Externalizable aList : list) {
         aList.writeExternal(out);
      }
   }
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:14,代码来源:SerializerUtils.java

示例5: write

import java.io.Externalizable; //导入方法依赖的package包/类
@Override
public void write(Externalizable object) {		
	int pos = activePosition;
	try {
		object.writeExternal(this);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
	assert(Pipe.validateVarLength(this.backingPipe, length(this)));
	assert(collectObjectSizeData(activePosition-pos));		
}
 
开发者ID:oci-pronghorn,项目名称:PronghornPipes,代码行数:12,代码来源:DataOutputBlobWriter.java

示例6: serializeObject

import java.io.Externalizable; //导入方法依赖的package包/类
public static byte[] serializeObject(Externalizable object)
        throws Exception {
    ByteArrayOutputStream baos;
    ObjectOutputStream oos = null;
    byte[] res = null;
    try {
        baos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(baos);

        object.writeExternal(oos);
        oos.flush();

        res = baos.toByteArray();

    } catch (Exception ex) {
        System.out.println("Error serializing object" + ex);
        throw ex;
    } finally {
        try {
            if (oos != null)
                oos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return res;
}
 
开发者ID:dhasenfratz,项目名称:hRouting_Android,代码行数:28,代码来源:GraphSerializerUtil.java

示例7: write

import java.io.Externalizable; //导入方法依赖的package包/类
@Override
public void write(Externalizable externalizable, BufferOutput buffer, Serializer serializer) {
  try {
    externalizable.writeExternal(new BufferObjectOutput(buffer, serializer));
  } catch (IOException e) {
    throw new SerializationException("failed to serialize externalizable type: " + externalizable.getClass(), e);
  }
}
 
开发者ID:atomix,项目名称:catalyst,代码行数:9,代码来源:ExternalizableSerializer.java

示例8: toBytes

import java.io.Externalizable; //导入方法依赖的package包/类
public static byte[] toBytes(Externalizable o) throws IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    o.writeExternal(out);
    out.flush();
    return baos.toByteArray();
}
 
开发者ID:mayconbordin,项目名称:streaminer,代码行数:9,代码来源:ExternalizableUtil.java

示例9: externalize

import java.io.Externalizable; //导入方法依赖的package包/类
private void externalize(final Externalizable original, final Externalizable copy) throws IOException, ClassNotFoundException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(baos);

    original.writeExternal(out);
    out.close();

    final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    final ObjectInputStream in = new ObjectInputStream(bais);

    copy.readExternal(in);
}
 
开发者ID:apache,项目名称:tomee,代码行数:13,代码来源:JndiRequestTest.java

示例10: marshal

import java.io.Externalizable; //导入方法依赖的package包/类
public void marshal(Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
    try {
        Externalizable externalizable = (Externalizable) source;
        CustomObjectOutputStream.StreamCallback callback = new CustomObjectOutputStream.StreamCallback() {
            public void writeToStream(Object object) {
                if (object == null) {
                    writer.startNode("null");
                    writer.endNode();
                } else {
                    ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object.getClass()), object.getClass());
                    context.convertAnother(object);
                    writer.endNode();
                }
            }

            public void writeFieldsToStream(Map fields) {
                throw new UnsupportedOperationException();
            }

            public void defaultWriteObject() {
                throw new UnsupportedOperationException();
            }

            public void flush() {
                writer.flush();
            }

            public void close() {
                throw new UnsupportedOperationException("Objects are not allowed to call ObjectOutput.close() from writeExternal()");
            }
        };
        CustomObjectOutputStream objectOutput = CustomObjectOutputStream.getInstance(context, callback);
        externalizable.writeExternal(objectOutput);
        objectOutput.popCallback();
    } catch (IOException e) {
        throw new ConversionException("Cannot serialize " + source.getClass().getName() + " using Externalization", e);
    }
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:39,代码来源:ExternalizableConverter.java

示例11: write

import java.io.Externalizable; //导入方法依赖的package包/类
@Override
public void write(Kryo kryo, Output output, Externalizable object) {
    KryoObjectOutput koo = new KryoObjectOutput(output, kryo);
    try {
        object.writeExternal(koo);
    } catch (IOException e) {
        //shouldn't happen
        throw new RuntimeException(e);
    }
}
 
开发者ID:splicemachine,项目名称:spliceengine,代码行数:11,代码来源:ExternalizableSerializer.java

示例12: marshal

import java.io.Externalizable; //导入方法依赖的package包/类
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
    try {
        final Externalizable externalizable = (Externalizable)source;
        final CustomObjectOutputStream.StreamCallback callback = new CustomObjectOutputStream.StreamCallback() {
            @Override
            public void writeToStream(final Object object) {
                if (object == null) {
                    writer.startNode("null");
                    writer.endNode();
                } else {
                    ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object
                        .getClass()), object.getClass());
                    context.convertAnother(object);
                    writer.endNode();
                }
            }

            @Override
            public void writeFieldsToStream(final Map<String, Object> fields) {
                throw new UnsupportedOperationException();
            }

            @Override
            public void defaultWriteObject() {
                throw new UnsupportedOperationException();
            }

            @Override
            public void flush() {
                writer.flush();
            }

            @Override
            public void close() {
                throw new UnsupportedOperationException(
                    "Objects are not allowed to call ObjectOutput.close() from writeExternal()");
            }
        };
        @SuppressWarnings("resource")
        final CustomObjectOutputStream objectOutput = CustomObjectOutputStream.getInstance(context, callback);
        externalizable.writeExternal(objectOutput);
        objectOutput.popCallback();
    } catch (final IOException e) {
        throw new ConversionException("Cannot serialize " + source.getClass().getName() + " using Externalization",
            e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:49,代码来源:ExternalizableConverter.java

示例13: outputObject

import java.io.Externalizable; //导入方法依赖的package包/类
private void outputObject(final Object obj) throws IOException{

        currentObject = obj;
        Class currclass = obj.getClass();

        /* Get the Class descriptor for this class,
         * Throw a NotSerializableException if there is none.
         */
        currentClassDesc = ObjectStreamClass.lookup(currclass);
        if (currentClassDesc == null) {
            // XXX I18N, Logging needed.
            throw new NotSerializableException(currclass.getName());
        }

        /* If the object is externalizable,
         * call writeExternal.
         * else do Serializable processing.
         */
        if (currentClassDesc.isExternalizable()) {
            // Write format version
            orbStream.write_octet(streamFormatVersion);

            Externalizable ext = (Externalizable)obj;
            ext.writeExternal(this);

        } else {

            /* The object's classes should be processed from supertype to subtype
             * Push all the clases of the current object onto a stack.
             * Remember the stack pointer where this set of classes is being pushed.
             */
            int stackMark = classDescStack.size();
            try {
                ObjectStreamClass next;
                while ((next = currentClassDesc.getSuperclass()) != null) {
                    classDescStack.push(currentClassDesc);
                    currentClassDesc = next;
                }

                /*
                 * For currentClassDesc and all the pushed class descriptors
                 *    If the class is writing its own data
                 *                set blockData = true; call the class writeObject method
                 *    If not
                 *     invoke either the defaultWriteObject method.
                 */
                do {

                    WriteObjectState oldState = writeObjectState;

                    try {

                        setState(NOT_IN_WRITE_OBJECT);

                        if (currentClassDesc.hasWriteObject()) {
                            invokeObjectWriter(currentClassDesc, obj );
                        } else {
                            defaultWriteObjectDelegate();
                        }
                    } finally {
                        setState(oldState);
                    }

                } while (classDescStack.size() > stackMark &&
                         (currentClassDesc = (ObjectStreamClass)classDescStack.pop()) != null);
            } finally {
                classDescStack.setSize(stackMark);
            }
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:71,代码来源:IIOPOutputStream.java

示例14: outputObject

import java.io.Externalizable; //导入方法依赖的package包/类
private void outputObject(final Object obj) throws IOException{

        currentObject = obj;
        Class currclass = obj.getClass();

        /* Get the Class descriptor for this class,
         * Throw a NotSerializableException if there is none.
         */
        currentClassDesc = ObjectStreamClass.lookup(currclass);
        if (currentClassDesc == null) {
            // XXX I18N, Logging needed.
            throw new NotSerializableException(currclass.getName());
        }

        /* If the object is externalizable,
         * call writeExternal.
         * else do Serializable processing.
         */
        if (currentClassDesc.isExternalizable()) {
            // Write format version
            orbStream.write_octet(streamFormatVersion);

            Externalizable ext = (Externalizable)obj;
            ext.writeExternal(this);

        } else {

            /* The object's classes should be processed from supertype to subtype
             * Push all the clases of the current object onto a stack.
             * Remember the stack pointer where this set of classes is being pushed.
             */
            if (currentClassDesc.forClass().getName().equals("java.lang.String")) {
                    this.writeUTF((String)obj);
                    return;
            }
            int stackMark = classDescStack.size();
            try {
                ObjectStreamClass next;
                while ((next = currentClassDesc.getSuperclass()) != null) {
                    classDescStack.push(currentClassDesc);
                    currentClassDesc = next;
                }

                /*
                 * For currentClassDesc and all the pushed class descriptors
                 *    If the class is writing its own data
                 *                set blockData = true; call the class writeObject method
                 *    If not
                 *     invoke either the defaultWriteObject method.
                 */
                do {

                    WriteObjectState oldState = writeObjectState;

                    try {

                        setState(NOT_IN_WRITE_OBJECT);

                        if (currentClassDesc.hasWriteObject()) {
                            invokeObjectWriter(currentClassDesc, obj );
                        } else {
                            defaultWriteObjectDelegate();
                        }
                    } finally {
                        setState(oldState);
                    }

                } while (classDescStack.size() > stackMark &&
                         (currentClassDesc = (ObjectStreamClass)classDescStack.pop()) != null);
            } finally {
                classDescStack.setSize(stackMark);
            }
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:75,代码来源:IIOPOutputStream.java

示例15: toStream

import java.io.Externalizable; //导入方法依赖的package包/类
public static void toStream(@Nonnull final Externalizable obj, @Nonnull final OutputStream out)
        throws IOException {
    ObjectOutputStream oos = new ObjectOutputStream(out);
    obj.writeExternal(oos);
    oos.flush();
}
 
开发者ID:apache,项目名称:incubator-hivemall,代码行数:7,代码来源:ObjectUtils.java


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