src/share/classes/java/rmi/MarshalledObject.java

Print this page




 139      *
 140      * @return a copy of the contained object
 141      * @exception IOException if an <code>IOException</code> occurs while
 142      * deserializing the object from its internal representation.
 143      * @exception ClassNotFoundException if a
 144      * <code>ClassNotFoundException</code> occurs while deserializing the
 145      * object from its internal representation.
 146      * could not be found
 147      * @since 1.2
 148      */
 149     public T get() throws IOException, ClassNotFoundException {
 150         if (objBytes == null)   // must have been a null object
 151             return null;
 152 
 153         ByteArrayInputStream bin = new ByteArrayInputStream(objBytes);
 154         // locBytes is null if no annotations
 155         ByteArrayInputStream lin =
 156             (locBytes == null ? null : new ByteArrayInputStream(locBytes));
 157         MarshalledObjectInputStream in =
 158             new MarshalledObjectInputStream(bin, lin);

 159         T obj = (T) in.readObject();
 160         in.close();
 161         return obj;
 162     }
 163 
 164     /**
 165      * Return a hash code for this <code>MarshalledObject</code>.
 166      *
 167      * @return a hash code
 168      */
 169     public int hashCode() {
 170         return hash;
 171     }
 172 
 173     /**
 174      * Compares this <code>MarshalledObject</code> to another object.
 175      * Returns true if and only if the argument refers to a
 176      * <code>MarshalledObject</code> that contains exactly the same
 177      * serialized representation of an object as this one does. The
 178      * comparison ignores any class codebase annotation, meaning that
 179      * two objects are equivalent if they have the same serialized
 180      * representation <i>except</i> for the codebase of each class
 181      * in the serialized representation.
 182      *
 183      * @param obj the object to compare with this <code>MarshalledObject</code>
 184      * @return <code>true</code> if the argument contains an equaivalent
 185      * serialized object; <code>false</code> otherwise
 186      * @since 1.2
 187      */
 188     public boolean equals(Object obj) {
 189         if (obj == this)
 190             return true;
 191 
 192         if (obj != null && obj instanceof MarshalledObject) {
 193             MarshalledObject other = (MarshalledObject) obj;
 194 
 195             // if either is a ref to null, both must be
 196             if (objBytes == null || other.objBytes == null)
 197                 return objBytes == other.objBytes;
 198 
 199             // quick, easy test
 200             if (objBytes.length != other.objBytes.length)
 201                 return false;
 202 
 203             //!! There is talk about adding an array comparision method
 204             //!! at 1.2 -- if so, this should be rewritten.  -arnold
 205             for (int i = 0; i < objBytes.length; ++i) {
 206                 if (objBytes[i] != other.objBytes[i])
 207                     return false;
 208             }
 209             return true;
 210         } else {
 211             return false;
 212         }
 213     }




 139      *
 140      * @return a copy of the contained object
 141      * @exception IOException if an <code>IOException</code> occurs while
 142      * deserializing the object from its internal representation.
 143      * @exception ClassNotFoundException if a
 144      * <code>ClassNotFoundException</code> occurs while deserializing the
 145      * object from its internal representation.
 146      * could not be found
 147      * @since 1.2
 148      */
 149     public T get() throws IOException, ClassNotFoundException {
 150         if (objBytes == null)   // must have been a null object
 151             return null;
 152 
 153         ByteArrayInputStream bin = new ByteArrayInputStream(objBytes);
 154         // locBytes is null if no annotations
 155         ByteArrayInputStream lin =
 156             (locBytes == null ? null : new ByteArrayInputStream(locBytes));
 157         MarshalledObjectInputStream in =
 158             new MarshalledObjectInputStream(bin, lin);
 159         @SuppressWarnings("unchecked")
 160         T obj = (T) in.readObject();
 161         in.close();
 162         return obj;
 163     }
 164 
 165     /**
 166      * Return a hash code for this <code>MarshalledObject</code>.
 167      *
 168      * @return a hash code
 169      */
 170     public int hashCode() {
 171         return hash;
 172     }
 173 
 174     /**
 175      * Compares this <code>MarshalledObject</code> to another object.
 176      * Returns true if and only if the argument refers to a
 177      * <code>MarshalledObject</code> that contains exactly the same
 178      * serialized representation of an object as this one does. The
 179      * comparison ignores any class codebase annotation, meaning that
 180      * two objects are equivalent if they have the same serialized
 181      * representation <i>except</i> for the codebase of each class
 182      * in the serialized representation.
 183      *
 184      * @param obj the object to compare with this <code>MarshalledObject</code>
 185      * @return <code>true</code> if the argument contains an equaivalent
 186      * serialized object; <code>false</code> otherwise
 187      * @since 1.2
 188      */
 189     public boolean equals(Object obj) {
 190         if (obj == this)
 191             return true;
 192 
 193         if (obj != null && obj instanceof MarshalledObject) {
 194             MarshalledObject<?> other = (MarshalledObject<?>) obj;
 195 
 196             // if either is a ref to null, both must be
 197             if (objBytes == null || other.objBytes == null)
 198                 return objBytes == other.objBytes;
 199 
 200             // quick, easy test
 201             if (objBytes.length != other.objBytes.length)
 202                 return false;
 203 
 204             //!! There is talk about adding an array comparision method
 205             //!! at 1.2 -- if so, this should be rewritten.  -arnold
 206             for (int i = 0; i < objBytes.length; ++i) {
 207                 if (objBytes[i] != other.objBytes[i])
 208                     return false;
 209             }
 210             return true;
 211         } else {
 212             return false;
 213         }
 214     }