diff options
| author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-03-10 21:46:48 +0000 |
|---|---|---|
| committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-03-10 21:46:48 +0000 |
| commit | ce57ab760f69de6db452def7ffbf5b114a2d8694 (patch) | |
| tree | ea38c56431c5d4528fb54254c3f8e50f517bede3 /libjava/classpath/java/rmi/MarshalledObject.java | |
| parent | 50996fe55769882de3f410896032c887f0ff0d04 (diff) | |
| download | gcc-ce57ab760f69de6db452def7ffbf5b114a2d8694.tar.gz | |
Imported GNU Classpath 0.90
* scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore.
* gnu/classpath/jdwp/VMFrame.java (SIZE): New constant.
* java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5.
* java/lang/Math.java: New override file.
* java/lang/Character.java: Merged from Classpath.
(start, end): Now 'int's.
(canonicalName): New field.
(CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants.
(UnicodeBlock): Added argument.
(of): New overload.
(forName): New method.
Updated unicode blocks.
(sets): Updated.
* sources.am: Regenerated.
* Makefile.in: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111942 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java/rmi/MarshalledObject.java')
| -rw-r--r-- | libjava/classpath/java/rmi/MarshalledObject.java | 103 |
1 files changed, 72 insertions, 31 deletions
diff --git a/libjava/classpath/java/rmi/MarshalledObject.java b/libjava/classpath/java/rmi/MarshalledObject.java index 9ec0ace0e70..e1a30f5f005 100644 --- a/libjava/classpath/java/rmi/MarshalledObject.java +++ b/libjava/classpath/java/rmi/MarshalledObject.java @@ -1,5 +1,6 @@ /* MarshalledObject.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. + Copyright (c) 1996, 1997, 1998, 1999, 2004, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,38 +43,68 @@ import gnu.java.rmi.RMIMarshalledObjectInputStream; import gnu.java.rmi.RMIMarshalledObjectOutputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.Serializable; /** - * FIXME - doc missing + * A <code>MarshalledObject</code> consists of a serialized object which is + * marshalled according to the RMI specification. + * <p> + * An object passed to the constructor is serialized and tagged with the needed + * URL to retrieve its class definition for remote usage. If the object is a + * remote reference its stub is serialized instead. The instance of this + * marshalled object can be later retrieved by its <code>get()</code> method. + * </p> + * + * @author unknown */ -public final class MarshalledObject implements Serializable +public final class MarshalledObject + implements Serializable { - //The following fields are from Java API Documentation "Serialized form" + // The following fields are from Java API Documentation "Serialized form" private static final long serialVersionUID = 8988374069173025854L; + byte[] objBytes; byte[] locBytes; int hash; - - public MarshalledObject(Object obj) throws java.io.IOException + + /** + * Constructs a <code>MarshalledObject</code> from the given object. + * + * @param obj the object to marshal + * @throws IOException if an I/O error during serialization occurs. + */ + public MarshalledObject(Object obj) throws IOException { ByteArrayOutputStream objStream = new ByteArrayOutputStream(); - RMIMarshalledObjectOutputStream stream = new RMIMarshalledObjectOutputStream(objStream); + RMIMarshalledObjectOutputStream stream = + new RMIMarshalledObjectOutputStream(objStream); stream.writeObject(obj); stream.flush(); objBytes = objStream.toByteArray(); locBytes = stream.getLocBytes(); - - //The following algorithm of calculating hashCode is similar to String + + // The following algorithm of calculating hashCode is similar to String hash = 0; for (int i = 0; i < objBytes.length; i++) hash = hash * 31 + objBytes[i]; - if(locBytes != null) + + if (locBytes != null) for (int i = 0; i < locBytes.length; i++) - hash = hash * 31 + locBytes[i]; + hash = hash * 31 + locBytes[i]; } - - public boolean equals(Object obj) + + /** + * Checks if the given object is equal to this marshalled object. + * + * <p>Marshalled objects are considered equal if they contain the + * same serialized object. Codebase annotations where the class + * definition can be downloaded are ignored in the equals test.</p> + * + * @param obj the object to compare. + * @return <code>true</code> if equal, <code>false</code> otherwise. + */ + public boolean equals(Object obj) { if (! (obj instanceof MarshalledObject)) return false; @@ -81,33 +112,43 @@ public final class MarshalledObject implements Serializable // hashCode even differs, don't do the time-consuming comparisons if (obj.hashCode() != hash) return false; - - MarshalledObject aobj = (MarshalledObject)obj; + + MarshalledObject aobj = (MarshalledObject) obj; if (objBytes == null || aobj.objBytes == null) return objBytes == aobj.objBytes; if (objBytes.length != aobj.objBytes.length) return false; - for (int i = 0; i < objBytes.length; i++) + for (int i = 0; i < objBytes.length; i++) { - if (objBytes[i] != aobj.objBytes[i]) - return false; + if (objBytes[i] != aobj.objBytes[i]) + return false; } // Ignore comparison of locBytes(annotation) return true; } - -public Object get() - throws java.io.IOException, java.lang.ClassNotFoundException -{ - if(objBytes == null) - return null; - RMIMarshalledObjectInputStream stream = - new RMIMarshalledObjectInputStream(objBytes, locBytes); - return stream.readObject(); -} - - public int hashCode() { + + /** + * Constructs and returns a copy of the internal serialized object. + * + * @return The deserialized object. + * + * @throws IOException if an I/O exception occurs during deserialization. + * @throws ClassNotFoundException if the class of the deserialized object + * cannot be found. + */ + public Object get() throws IOException, ClassNotFoundException + { + if (objBytes == null) + return null; + + RMIMarshalledObjectInputStream stream = + new RMIMarshalledObjectInputStream(objBytes, locBytes); + return stream.readObject(); + } + + public int hashCode() + { return hash; } - + } |
