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


Java ObjectInputStream.readObject方法代码示例

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


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

示例1: doReps

import java.io.ObjectInputStream; //导入方法依赖的package包/类
/**
 * Run benchmark for given number of batches, with each batch containing
 * the given number of cycles.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, Node[] trees, int nbatches)
    throws Exception
{
    int ncycles = trees.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeObject(trees[j]);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readObject();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ReplaceTrees.java

示例2: testSerializationAndCloning

import java.io.ObjectInputStream; //导入方法依赖的package包/类
private final void testSerializationAndCloning(Tree node) throws Exception {

		// Serialize
		ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
		ObjectOutputStream oos = new ObjectOutputStream(baos);
		oos.writeObject(node);
		oos.flush();
		byte[] bytes = baos.toByteArray();
		// System.out.println(new String(bytes));

		// Deserialize
		ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
		ObjectInputStream ois = new ObjectInputStream(bais);
		Tree copy = (Tree) ois.readObject();

		String txtOriginal = node.toString("debug");
		String txtCopy = copy.toString("debug");

		assertEquals(txtOriginal, txtCopy);

		// Cloning
		txtCopy = node.clone().toString("debug");
		assertEquals(txtOriginal, txtCopy);
	}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:25,代码来源:ExtendedTreeTest.java

示例3: doReps

import java.io.ObjectInputStream; //导入方法依赖的package包/类
/**
 * Run benchmark for given number of batches.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, Node[] objs, int nbatches)
    throws Exception
{
    int nobjs = objs.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        for (int j = 0; j < nobjs; j++) {
            oout.writeObject(objs[j]);
        }
        oout.flush();
        for (int j = 0; j < nobjs; j++) {
            oin.readObject();
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:RepeatObjs.java

示例4: readObject

import java.io.ObjectInputStream; //导入方法依赖的package包/类
private void readObject(ObjectInputStream s)
  throws ClassNotFoundException, IOException
{
  s.defaultReadObject();

  Object keyOrNull;
  while(null != (keyOrNull = s.readObject())) {
    String key = ((String)keyOrNull).intern();

    if (itemListenerK == key)
      addItemListener((ItemListener)(s.readObject()));

    else // skip value for unrecognized key
      s.readObject();
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:CheckboxMenuItem.java

示例5: readObject

import java.io.ObjectInputStream; //导入方法依赖的package包/类
public void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    Object obj = in.readObject();

    if (obj instanceof Hashtable)
    {
        this.pkcs12Attributes = (Hashtable)obj;
        this.pkcs12Ordering = (Vector)in.readObject();
    }
    else
    {
        ASN1InputStream aIn = new ASN1InputStream((byte[])obj);

        ASN1ObjectIdentifier    oid;

        while ((oid = (ASN1ObjectIdentifier)aIn.readObject()) != null)
        {
            this.setBagAttribute(oid, aIn.readObject());
        }
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:23,代码来源:PKCS12BagAttributeCarrierImpl.java

示例6: test

import java.io.ObjectInputStream; //导入方法依赖的package包/类
private static void test(String className) throws Exception {
    Class<?> c = Class.forName(className);
    Field f = c.getField("BYTES");
    byte[] bytes = (byte[]) f.get(null);
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    ObjectInputStream ois = new ObjectInputStream(bis);
    boolean matched = true;
    for (Serializable s : objects) {
        Object o = ois.readObject();
        if (!o.equals(s)) {
            showMismatch(o, s);
            matched = false;
        }
    }
    if (!matched)
        throw new Exception("Read objects did not match");
    System.out.println("Test passed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:MBeanInfoInteropTest.java

示例7: readObject

import java.io.ObjectInputStream; //导入方法依赖的package包/类
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
    s.defaultReadObject();
    this.count = 0;
    this.first = null;
    this.last = null;
    while (true) {
        E item = s.readObject();
        if (item != null) {
            add(item);
        } else {
            return;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:15,代码来源:LinkedBlockingDeque.java

示例8: readObject

import java.io.ObjectInputStream; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
	this._featureIntMap = (HashMap<String, HashMap<String, HashMap<String, Integer>>>)in.readObject();
	this._feature2rep = (String[][])in.readObject();
	this._weights = (double[])in.readObject();
	this._size = in.readInt();
	this._fixedFeaturesSize = in.readInt();
	this._locked = in.readBoolean();
}
 
开发者ID:justhalf,项目名称:weak-semi-crf-naacl2016,代码行数:10,代码来源:GlobalNetworkParam.java

示例9: deserialize

import java.io.ObjectInputStream; //导入方法依赖的package包/类
private static Object deserialize(byte[] buf, int len) throws IOException, ClassNotFoundException {
    final ByteArrayInputStream bis = new ByteArrayInputStream(buf, 0, len);
    final ObjectInputStream ois = new ObjectInputStream(bis);
    final Object object = ois.readObject();
    ois.close();
    bis.close();
    return object;
}
 
开发者ID:eps4j,项目名称:eps4j-core,代码行数:9,代码来源:EPSComm.java

示例10: getDeviceData

import java.io.ObjectInputStream; //导入方法依赖的package包/类
/**
 * 将对象从shareprerence中取出来
 *
 * @param key
 * @param <T>
 * @return
 */
public static <T> T getDeviceData(Context context, String key) {
    if (mSharedPreferences == null) {
        mSharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    }
    T device = null;
    String productBase64 = mSharedPreferences.getString(key, null);

    if (productBase64 == null) {
        return null;
    }
    // 读取字节
    byte[] base64 = Base64.decode(productBase64.getBytes(), Base64.DEFAULT);

    // 封装到字节流
    ByteArrayInputStream bais = new ByteArrayInputStream(base64);
    try {
        // 再次封装
        ObjectInputStream bis = new ObjectInputStream(bais);

        // 读取对象
        device = (T) bis.readObject();

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return device;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:DataHelper.java

示例11: unzip

import java.io.ObjectInputStream; //导入方法依赖的package包/类
public static Object unzip(byte[] blob) throws IOException, ClassNotFoundException {
  // logger.info("CacheServerHelper: Unzipping blob to object: " + blob);
  ByteArrayInputStream bais = new ByteArrayInputStream(blob);
  GZIPInputStream gs = new GZIPInputStream(bais);
  ObjectInputStream ois = new ObjectInputStream(gs);
  Object obj = ois.readObject();
  // logger.info("CacheServerHelper: Unzipped blob to object: " + obj);
  ois.close();
  bais.close();
  return obj;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:12,代码来源:CacheServerHelper.java

示例12: readObject

import java.io.ObjectInputStream; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException{
	tokenizerMethod = (TokenizerMethod)ois.readObject();
	brownMap = (Map<String, String>)ois.readObject();
	for(FeatureType featureType: FeatureType.values()){
		featureType.isEnabled = ois.readBoolean();
	}
	try{
		prefixLength = ois.readInt();
		suffixLength = ois.readInt();
	} catch (Exception e){
		
	}
}
 
开发者ID:justhalf,项目名称:weak-semi-crf-naacl2016,代码行数:15,代码来源:WordWeakSemiCRFFeatureManager.java

示例13: readObject

import java.io.ObjectInputStream; //导入方法依赖的package包/类
@GwtIncompatible("java.io.ObjectInputStream")
@SuppressWarnings("unchecked") // reading data stored by writeObject
private void readObject(ObjectInputStream stream)
    throws IOException, ClassNotFoundException {
  stream.defaultReadObject();
  factory = (Supplier<? extends List<V>>) stream.readObject();
  Map<K, Collection<V>> map = (Map<K, Collection<V>>) stream.readObject();
  setMap(map);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:10,代码来源:Multimaps.java

示例14: readObject

import java.io.ObjectInputStream; //导入方法依赖的package包/类
private void readObject(final ObjectInputStream in)
        throws IOException, ClassNotFoundException {

    @SuppressWarnings("unchecked") final Map<String, Object> map =
            (Map<String, Object>) in.readObject();

    _data = (float[][][]) map.get("data");
    _variance = (Double) map.get("variance");

    final int version = (Integer) map.get("VERSION");
    if (version != VERSION) {
        Logger.getLogger(getClass().getName()).warning
                ("Need to convert data from version " + version + " to " + VERSION);
    }
}
 
开发者ID:MinesJTK,项目名称:jtk,代码行数:16,代码来源:ArrayVect3f.java

示例15: readObject

import java.io.ObjectInputStream; //导入方法依赖的package包/类
/**
 * Deserializes an {@link MBeanFeatureInfo} from an {@link ObjectInputStream}.
 * @serialData
 * For compatibility reasons, an object of this class is deserialized as follows.
 * <p>
 * The method {@link ObjectInputStream#defaultReadObject defaultReadObject()}
 * is called first to deserialize the object except the field
 * {@code descriptor}, which is not serialized in the default way. Then the method
 * {@link ObjectInputStream#read read()} is called to read a byte, the field
 * {@code descriptor} is deserialized according to the value of the byte value:
 *    <ul>
 *    <li>1. The method {@link ObjectInputStream#readObject readObject()}
 *       is called twice to obtain the field names (a {@code String[]}) and
 *       the field values (a {@code Object[]}) of the {@code descriptor}.
 *       The two obtained values then are used to construct
 *       an {@link ImmutableDescriptor} instance for the field
 *       {@code descriptor};</li>
 *    <li>0. The value for the field {@code descriptor} is obtained directly
 *       by calling the method {@link ObjectInputStream#readObject readObject()}.
 *       If the obtained value is null, the field {@code descriptor} is set to
 *       {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR};</li>
 *    <li>-1. This means that there is no byte to read and that the object is from
 *       an earlier version of the JMX API. The field {@code descriptor} is set
 *       to {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR}</li>
 *    <li>Any other value. A {@link StreamCorruptedException} is thrown.</li>
 *    </ul>
 *
 * @since 1.6
 */
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException {

    in.defaultReadObject();

    switch (in.read()) {
    case 1:
        final String[] names = (String[])in.readObject();

        final Object[] values = (Object[]) in.readObject();
        descriptor = (names.length == 0) ?
            ImmutableDescriptor.EMPTY_DESCRIPTOR :
            new ImmutableDescriptor(names, values);

        break;
    case 0:
        descriptor = (Descriptor)in.readObject();

        if (descriptor == null) {
            descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
        }

        break;
    case -1: // from an earlier version of the JMX API
        descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;

        break;
    default:
        throw new StreamCorruptedException("Got unexpected byte.");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:61,代码来源:MBeanFeatureInfo.java


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