Пример #1
0
  /**
   * Write the specified object to the ObjectOutputStream. Objects referenced by this object are
   * written transitively so that a complete equivalent graph of objects can be reconstructed by an
   * ObjectInputStream.
   *
   * <p>Exceptions are thrown for problems with the OutputStream and for classes that should not be
   * serialized. All exceptions are fatal to the OutputStream, which is left in an indeterminate
   * state, and it is up to the caller to ignore or recover the stream state.
   *
   * @throws IOException Any exception thrown by the underlying OutputStream.
   */
  public final void writeObject(Object obj) throws IOException {
    try {
      // Find an appropriate surrogate for the object
      SerializationSurrogate surrogate = this.mSelector.getSurrogateForObject(obj, _cacheContext);
      // write type handle

      Class[] type;
      if (surrogate instanceof ObjectSerializationSurrogate) {
        SerializationSurrogate testSurrogate = null;

        testSurrogate = getType(surrogate, obj.getClass());

        if (testSurrogate != null) {
          surrogate = testSurrogate;
        }
      }

      surrogate.writeHandle(this, obj);
      if (surrogate.getSubHandle() > 0) surrogate.writeSubHandle(this, obj);
      surrogate.writeObject(this, obj);
    } catch (CacheIOException nCacheIOException) {
      // this.writeObject(obj);
      throw new IOException(nCacheIOException.toString() + " is not marked as serializable.");
    } catch (Exception ex) {
      throw new IOException(ex.toString());
    }
  }
Пример #2
0
  /**
   * Write the specified object to the ObjectOutputStream. Objects referenced by this object are
   * written transitively so that a complete equivalent graph of objects can be reconstructed by an
   * ObjectInputStream.
   *
   * <p>Exceptions are thrown for problems with the OutputStream and for classes that should not be
   * serialized. All exceptions are fatal to the OutputStream, which is left in an indeterminate
   * state, and it is up to the caller to ignore or recover the stream state.
   *
   * @param obj the object to be written
   * @param objClass the class surrogate to use for writing the object.
   * @exception IOException Any of the usual Input/Output related exceptions.
   * @throws IOException Any exception thrown by the underlying OutputStream.
   */
  public void writeObject(Object obj, Class objClass) throws IOException {
    if (obj == null) {
      throw new NullPointerException("obj");
    }
    if (objClass == null) {
      throw new NullPointerException("objClass");
    }

    try {
      SerializationSurrogate surrogate =
          this.mSelector.getSurrogateForType(objClass, _cacheContext);
      surrogate.writeObject(this, obj);
    } catch (Exception ex) {
      throw new IOException(ex.toString());
    }
  }