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