Java 类java.io.ObjectInputStream 实例源码

项目:asura    文件:WebLogicDelegate.java   
/**
 * <p>
 * This method should be overridden by any delegate subclasses that need
 * special handling for BLOBs. The default implementation uses standard
 * JDBC <code>java.sql.Blob</code> operations.
 * </p>
 * 
 * @param rs
 *          the result set, already queued to the correct row
 * @param colName
 *          the column name for the BLOB
 * @return the deserialized Object from the ResultSet BLOB
 * @throws ClassNotFoundException
 *           if a class found during deserialization cannot be found
 * @throws IOException
 *           if deserialization causes an error
 */
protected Object getObjectFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {

    Object obj = null;

    Blob blobLocator = rs.getBlob(colName);
    InputStream binaryInput = null;
    try {
        if (null != blobLocator && blobLocator.length() > 0) {
            binaryInput = blobLocator.getBinaryStream();
        }
    } catch (Exception ignore) {
    }

    if (null != binaryInput) {
        ObjectInputStream in = new ObjectInputStream(binaryInput);
        try {
            obj = in.readObject();
        } finally {
            in.close();
        }
    }

    return obj;
}
项目:jdk8u-jdk    文件:ReadObject.java   
private static Object copyObject(Object oldObj) {
    Object newObj = null;
    try {
       //Create a stream in which to serialize the object.
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        ObjectOutputStream p = new ObjectOutputStream(ostream);
        //Serialize the object into the stream
        p.writeObject(oldObj);

        //Create an input stream from which to deserialize the object
        byte[] byteArray = ostream.toByteArray();
        ByteArrayInputStream istream = new ByteArrayInputStream(byteArray);
        ObjectInputStream q = new ObjectInputStream(istream);
        //Deserialize the object
        newObj = q.readObject();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return newObj;
}
项目:quidditchtimekeeper    文件:SerializerClass.java   
public static Object deserializeObject(byte[] b) {
    try {
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(b));
        Object object = in.readObject();
        in.close();

        return object;
    } catch(ClassNotFoundException cnfe) {
        Log.e("deserializeObject", "class not found error", cnfe);

        return null;
    } catch(IOException ioe) {
        Log.e("deserializeObject", "io error", ioe);

        return null;
    }
}
项目:openjdk-jdk10    文件:IntArrays.java   
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, int[][] arrays, int nbatches)
    throws Exception
{
    int ncycles = arrays.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeObject(arrays[j]);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readObject();
        }
    }
}
项目:jdk8u-jdk    文件:Scrollbar.java   
/**
 * Reads the <code>ObjectInputStream</code> and if
 * it isn't <code>null</code> adds a listener to
 * receive adjustment events fired by the
 * <code>Scrollbar</code>.
 * Unrecognized keys or values will be ignored.
 *
 * @param s the <code>ObjectInputStream</code> to read
 * @exception HeadlessException if
 *   <code>GraphicsEnvironment.isHeadless</code> returns
 *   <code>true</code>
 * @see java.awt.GraphicsEnvironment#isHeadless
 * @see #writeObject(ObjectOutputStream)
 */
private void readObject(ObjectInputStream s)
  throws ClassNotFoundException, IOException, HeadlessException
{
  GraphicsEnvironment.checkHeadless();
  s.defaultReadObject();

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

    if (adjustmentListenerK == key)
      addAdjustmentListener((AdjustmentListener)(s.readObject()));

    else // skip value for unrecognized key
      s.readObject();
  }
}
项目:jdk8u-jdk    文件:CommunicatorServer.java   
/**
 * Controls the way the CommunicatorServer service is deserialized.
 */
private void readObject(ObjectInputStream stream)
    throws IOException, ClassNotFoundException {

    // Call the default deserialization of the object.
    //
    stream.defaultReadObject();

    // Call the specific initialization for the CommunicatorServer service.
    // This is for transient structures to be initialized to specific
    // default values.
    //
    stateLock = new Object();
    state = OFFLINE;
    stopRequested = false;
    servedClientCount = 0;
    clientHandlerVector = new Vector<>();
    mainThread = null;
    notifCount = 0;
    notifInfos = null;
    notifBroadcaster = new NotificationBroadcasterSupport();
    dbgTag = makeDebugTag();
}
项目:jodis-client    文件:CacheUtils.java   
/**
 * 
 * 功能描述:自己数组转换成对象 <br>
 * 〈功能详细描述〉
 *
 * @param bytes bytes
 * @return object
 * @throws IOException ioexception
 * @see [相关类/方法](可选)
 * @since [产品/模块版本](可选)
 */
public static Object byteArrayToObject(byte[] bytes) throws IOException {
    if (bytes == null || bytes.length <= 0) {
        return null;
    }
    Object obj = null;
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(bis));
        obj = ois.readObject();
        bis.close();
        ois.close();
    } catch (ClassNotFoundException e) {
        logger.error(e.getMessage());
    }
    return obj;
}
项目:Robin_Java    文件:UnsafeTest.java   
public static void main( String[] args ) throws IOException, ClassNotFoundException
{
    Person obj = new Person();
    obj.setName( "Robin" );

    PersonHack objH = new PersonHack();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(objH);

    //反序列化漏洞,如果反序列化的對象可以試任意的,則有可能執行任意有風險額代碼
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream  ois = new ObjectInputStream(bais);

    Person objCopy = (Person)ois.readObject();        
    System.out.println(objCopy.getName());

}
项目:openjdk-jdk10    文件:SocketPermission.java   
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    // Don't call in.defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get the one we want
    @SuppressWarnings("unchecked")
    Vector<SocketPermission> permissions = (Vector<SocketPermission>)gfields.get("permissions", null);
    perms = new ConcurrentSkipListMap<>(new SPCComparator());
    for (SocketPermission sp : permissions) {
        perms.put(sp.getName(), sp);
    }
}
项目:jdk8u-jdk    文件:CharArrays.java   
/**
 * Write and read char arrays to/from a stream.  The benchmark is run in
 * batches, with each batch consisting of a fixed number of read/write
 * cycles.  The ObjectOutputStream is reset after each batch of cycles has
 * completed.
 * Arguments: <array size> <# batches> <# cycles per batch>
 */
public long run(String[] args) throws Exception {
    int size = Integer.parseInt(args[0]);
    int nbatches = Integer.parseInt(args[1]);
    int ncycles = Integer.parseInt(args[2]);
    char[][] arrays = new char[ncycles][size];
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());

    doReps(oout, oin, sbuf, arrays, 1);     // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, arrays, nbatches);
    return System.currentTimeMillis() - start;
}
项目:openjdk-jdk10    文件:SuppressStackTraces.java   
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    in.defaultReadObject();

    /*
     * Verify right at unmarshalling time that this exception instance
     * contains no stack trace data from the server (regardless of whether
     * or not it would be apparent at the RMI client application level).
     */
    StackTraceElement[] trace = getStackTrace();
    if (trace.length > 0) {
        throw new RuntimeException(
            "TEST FAILED: exception contained non-empty stack trace: " +
            Arrays.asList(trace));
    }
}
项目:openjdk-jdk10    文件:Longs.java   
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, int nbatches, int ncycles)
    throws Exception
{
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeLong(0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readLong();
        }
    }
}
项目:incubator-netbeans    文件:SharedClassObject.java   
/** Read object.
*/
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException {
    ois.defaultReadObject();

    if (clazz == null) {
        // Means that the class is no longer available in the restoring classloader.
        // Normal enough if the module has been uninstalled etc. #15654
        if (name != null) {
            throw new ClassNotFoundException(name);
        } else {
            // Compatibility with older WR's.
            throw new ClassNotFoundException();
        }
    }

    object = findObject(clazz, true);
    object.inReadExternal = true;

    try {
        object.readExternal(ois);
    } finally {
        object.inReadExternal = false;
    }
}
项目:jdk8u-jdk    文件:Doubles.java   
/**
 * Write and read double values to/from a stream.  The benchmark is run in
 * batches: each "batch" consists of a fixed number of read/write cycles,
 * and the stream is flushed (and underlying stream buffer cleared) in
 * between each batch.
 * Arguments: <# batches> <# cycles per batch>
 */
public long run(String[] args) throws Exception {
    int nbatches = Integer.parseInt(args[0]);
    int ncycles = Integer.parseInt(args[1]);
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());

    doReps(oout, oin, sbuf, 1, ncycles);    // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, nbatches, ncycles);
    return System.currentTimeMillis() - start;
}
项目:jdk8u-jdk    文件:RepeatObjs.java   
/**
 * Write and read repeated objects to/from a stream.  The benchmark is run
 * for a given number of batches.  Within each batch, a set of objects
 * is written to and read from the stream.  The set of objects remains the
 * same between batches (and the serialization streams are not reset) in
 * order to test the speed of object -> wire handle lookup, and vice versa.
 * Arguments: <# objects> <# cycles>
 */
public long run(String[] args) throws Exception {
    int size = Integer.parseInt(args[0]);
    int nbatches = Integer.parseInt(args[1]);
    Node[] objs = genObjs(size);
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());

    doReps(oout, oin, sbuf, objs, 1);       // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, objs, nbatches);
    return System.currentTimeMillis() - start;
}
项目:RxEasyHttp    文件:SerializableOkHttpCookies.java   
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    long expiresAt = in.readLong();
    String domain = (String) in.readObject();
    String path = (String) in.readObject();
    boolean secure = in.readBoolean();
    boolean httpOnly = in.readBoolean();
    boolean hostOnly = in.readBoolean();
    //boolean persistent = in.readBoolean();
    Cookie.Builder builder = new Cookie.Builder();
    builder = builder.name(name);
    builder = builder.value(value);
    builder = builder.expiresAt(expiresAt);
    builder = hostOnly ? builder.hostOnlyDomain(domain) : builder.domain(domain);
    builder = builder.path(path);
    builder = secure ? builder.secure() : builder;
    builder = httpOnly ? builder.httpOnly() : builder;
    clientCookies =builder.build();
}
项目:underlx    文件:ExtraContentCache.java   
@Nullable
private String retrieveConnectionInfo(int maxAgeDays, String stationId, String type, String locale) {
    try {
        FileInputStream fis = new FileInputStream(new File(context.getCacheDir(), String.format(CONN_INFO_CACHE_FILENAME, stationId, type, locale)));
        ObjectInputStream is = new ObjectInputStream(fis);
        CachedConnectionInfo cached = (CachedConnectionInfo) is.readObject();
        is.close();
        fis.close();

        if (cached.date.getTime() < new Date().getTime() - 1000 * 60 * 60 * 24 * maxAgeDays && Connectivity.isConnected(context)) {
            return null;
        }
        return cached.html;
    } catch (Exception e) {
        // oh well, we'll have to do without cache
        // caching is best-effort
        return null;
    }
}
项目:jdk8u-jdk    文件:Doubles.java   
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, int nbatches, int ncycles)
    throws Exception
{
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeDouble(0.0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readDouble();
        }
    }
}
项目:lams    文件:OracleDelegate.java   
@Override
protected Object getObjectFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {

    Object obj = null;
    InputStream binaryInput = rs.getBinaryStream(colName);
    if (binaryInput != null) {
        ObjectInputStream in = new ObjectInputStream(binaryInput);
        try {
            obj = in.readObject();
        } finally {
            in.close();
        }
    }

    return obj;
}
项目:apache-tomcat-7.0.73-with-comment    文件:XByteBuffer.java   
public static Serializable deserialize(byte[] data, int offset, int length, ClassLoader[] cls) 
    throws IOException, ClassNotFoundException, ClassCastException {
    invokecount.addAndGet(1);
    Object message = null;
    if ( cls == null ) cls = new ClassLoader[0];
    if (data != null && length > 0) {
        InputStream  instream = new ByteArrayInputStream(data,offset,length);
        ObjectInputStream stream = null;
        stream = (cls.length>0)? new ReplicationStream(instream,cls):new ObjectInputStream(instream);
        message = stream.readObject();
        instream.close();
        stream.close();
    }
    if ( message == null ) {
        return null;
    } else if (message instanceof Serializable)
        return (Serializable) message;
    else {
        throw new ClassCastException("Message has the wrong class. It should implement Serializable, instead it is:"+message.getClass().getName());
    }
}
项目:s-store    文件:MapMakerInternalMap.java   
@SuppressWarnings("deprecation") // serialization of deprecated feature
MapMaker readMapMaker(ObjectInputStream in) throws IOException {
  int size = in.readInt();
  MapMaker mapMaker = new MapMaker()
      .initialCapacity(size)
      .setKeyStrength(keyStrength)
      .setValueStrength(valueStrength)
      .keyEquivalence(keyEquivalence)
      .concurrencyLevel(concurrencyLevel);
  mapMaker.removalListener(removalListener);
  if (expireAfterWriteNanos > 0) {
    mapMaker.expireAfterWrite(expireAfterWriteNanos, TimeUnit.NANOSECONDS);
  }
  if (expireAfterAccessNanos > 0) {
    mapMaker.expireAfterAccess(expireAfterAccessNanos, TimeUnit.NANOSECONDS);
  }
  if (maximumSize != MapMaker.UNSET_INT) {
    mapMaker.maximumSize(maximumSize);
  }
  return mapMaker;
}
项目:jlayer    文件:JavaLayerUtils.java   
/**
 * Deserializes an object from the given <code>InputStream</code>.
 * The deserialization is delegated to an <code>
 * ObjectInputStream</code> instance. 
 * 
 * @param in    The <code>InputStream</code> to deserialize an object
 *              from.
 * 
 * @return The object deserialized from the stream. 
 * @exception IOException is thrown if there was a problem reading
 *      the underlying stream, or an object could not be deserialized
 *      from the stream.
 * 
 * @see java.io.ObjectInputStream
 */
static public Object deserialize(InputStream in)
    throws IOException
{
    if (in==null)
        throw new NullPointerException("in");

    ObjectInputStream objIn = new ObjectInputStream(in);

    Object obj;

    try
    {
        obj = objIn.readObject();
    }
    catch (ClassNotFoundException ex)
    {
        throw new InvalidClassException(ex.toString());
    }

    return obj;
}
项目:whackpad    文件:UintMap.java   
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    in.defaultReadObject();

    int writtenKeyCount = keyCount;
    if (writtenKeyCount != 0) {
        keyCount = 0;
        boolean hasIntValues = in.readBoolean();
        boolean hasObjectValues = in.readBoolean();

        int N = 1 << power;
        if (hasIntValues) {
            keys = new int[2 * N];
            ivaluesShift = N;
        }else {
            keys = new int[N];
        }
        for (int i = 0; i != N; ++i) {
            keys[i] = EMPTY;
        }
        if (hasObjectValues) {
            values = new Object[N];
        }
        for (int i = 0; i != writtenKeyCount; ++i) {
            int key = in.readInt();
            int index = insertNewKey(key);
            if (hasIntValues) {
                int ivalue = in.readInt();
                keys[ivaluesShift + index] = ivalue;
            }
            if (hasObjectValues) {
                values[index] = in.readObject();
            }
        }
    }
}
项目:mDL-ILP    文件:StorageUtils.java   
public static Object loadObject(Context context, String key) {
    try (ObjectInputStream os = new ObjectInputStream(context.getApplicationContext().openFileInput(key))) {
        return os.readObject();
    } catch (IOException | ClassNotFoundException e) {
        Log.e("StorageUtils", "Error loading object", e);
    }

    return null;
}
项目:Java_Swing_Programming    文件:Soru2Okuma.java   
public static void main(String[] args) throws IOException {
    try {
        ObjectInputStream oOS=new ObjectInputStream(new BufferedInputStream(new FileInputStream("Ayşe")));
        System.out.println(oOS.readUTF());
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Soru2Okuma.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:OpenJSharp    文件:JapaneseImperialCalendar.java   
/**
 * Updates internal state.
 */
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (jdate == null) {
        jdate = jcal.newCalendarDate(getZone());
        cachedFixedDate = Long.MIN_VALUE;
    }
}
项目:logistimo-web-service    文件:EventSummaryConfigModel.java   
public EventSummaryConfigModel copy() throws IOException, ClassNotFoundException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
    objectOutputStream.writeObject(this);
    ByteArrayInputStream
        byteArrayInputStream =
        new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
    return (EventSummaryConfigModel) objectInputStream.readObject();

}
项目:openjdk-jdk10    文件:TCKChronoPeriod.java   
@Test(dataProvider="calendars")
public void test_serialization(Chronology chrono) throws Exception {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    out.writeObject(period);
    out.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

    ObjectInputStream in = new ObjectInputStream(bais);
    ChronoPeriod ser = (ChronoPeriod) in.readObject();
    assertEquals(ser, period, "deserialized ChronoPeriod is wrong");
}
项目:morpheus-core    文件:SparseArrayOfZonedDateTimes.java   
@Override
public final void read(ObjectInputStream is, int count) throws IOException {
    for (int i=0; i<count; ++i) {
        final long value = is.readLong();
        this.values.put(i, value);
        if (value != defaultValueAsLong) {
            final short zoneId = is.readShort();
            this.zoneIds.put(i, zoneId);
        }
    }
}
项目:Pogamut3    文件:TCMessageData.java   
@SuppressWarnings("unused")
private void readObject(ObjectInputStream ois) {
    try {
        ois.defaultReadObject();            
        if (this.messageType != null) {
            this.messageType = Tokens.get(this.messageType.getToken());
        }
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception e) {
        throw new RuntimeException("Failed to deserialize the object.", e);
    }
}
项目:Orsum-occulendi    文件:RSAUtil.java   
public static PrivateKey privateKeyFromString(String exported) throws IOException, ClassNotFoundException {
    byte [] data = Base64.getDecoder().decode(exported);
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
    PrivateKey o = (PrivateKey)ois.readObject();
    ois.close();
    return o;
}
项目:letv    文件:bi.java   
private void a(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
    try {
        this.i = (byte) 0;
        a(new cs(new dk((InputStream) objectInputStream)));
    } catch (cf e) {
        throw new IOException(e.getMessage());
    }
}
项目:GitHub    文件:BodyRequest.java   
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    String mediaTypeString = (String) in.readObject();
    if (!TextUtils.isEmpty(mediaTypeString)) {
        mediaType = MediaType.parse(mediaTypeString);
    }
}
项目:MyFlightbookAndroid    文件:MFBUtil.java   
public static <T> T deserializeFromString(String s) {
    if (s == null || s.length() == 0)
        return null;

    try {
        byte rgb[] = Base64.decode(s, Base64.DEFAULT);
        ByteArrayInputStream bis = new ByteArrayInputStream(rgb);
        ObjectInputStream ois = new ObjectInputStream(bis);
        //noinspection unchecked
        return (T) ois.readObject();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
项目:letv    文件:bk.java   
private void a(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
    try {
        this.j = (byte) 0;
        a(new cs(new dk((InputStream) objectInputStream)));
    } catch (cf e) {
        throw new IOException(e.getMessage());
    }
}
项目:android-project-gallery    文件:SerializableCookie.java   
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    clientCookie = new BasicClientCookie(name, value);
    clientCookie.setComment((String) in.readObject());
    clientCookie.setDomain((String) in.readObject());
    clientCookie.setExpiryDate((Date) in.readObject());
    clientCookie.setPath((String) in.readObject());
    clientCookie.setVersion(in.readInt());
    clientCookie.setSecure(in.readBoolean());
}
项目:ipack    文件:JDKDSAPublicKey.java   
private void readObject(
    ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    this.y = (BigInteger)in.readObject();
    this.dsaSpec = new DSAParameterSpec((BigInteger)in.readObject(), (BigInteger)in.readObject(), (BigInteger)in.readObject());
}
项目:NoRiskNoFun    文件:AttackMessagesTests.java   
@Test
public void DiceAmount() throws IOException, ClassNotFoundException {

    DiceAmount diceAmount = new DiceAmount(10);
    diceAmount.setAmount(10);
    oos.writeObject (diceAmount);
    ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray ());
    ObjectInputStream ois = new ObjectInputStream (bais);
    DiceAmount diceAmount1 =(DiceAmount) ois.readObject();
    assertEquals(diceAmount1.getAmount(),  10);

}
项目:TuLiPA-frames    文件:CollectionUtilities.java   
public static Object deepCopy(Object original) throws Exception {
    Object ret = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bos);
    out.writeObject(original);
    out.flush();
    out.close();
    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
    ret = in.readObject();
    return ret;
}
项目:openjdk-jdk10    文件:ChoiceFormat.java   
/**
 * After reading an object from the input stream, do a simple verification
 * to maintain class invariants.
 * @throws InvalidObjectException if the objects read from the stream is invalid.
 */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    if (choiceLimits.length != choiceFormats.length) {
        throw new InvalidObjectException(
                "limits and format arrays of different length.");
    }
}