/[classpath]/classpath/java/rmi/MarshalledObject.java
ViewVC logotype

Diff of /classpath/java/rmi/MarshalledObject.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by mark, Tue Jan 22 22:27:00 2002 UTC revision 1.3 by cbj, Mon Mar 25 05:12:19 2002 UTC
# Line 38  exception statement from your version. * Line 38  exception statement from your version. *
38  package java.rmi;  package java.rmi;
39    
40  import java.io.Serializable;  import java.io.Serializable;
41    import java.io.ByteArrayOutputStream;
42    import java.io.IOException;
43    import gnu.java.rmi.RMIMarshalledObjectInputStream;
44    import gnu.java.rmi.RMIMarshalledObjectOutputStream;
45    
46    /**
47     * FIXME - doc missing
48     */
49  public final class MarshalledObject  public final class MarshalledObject
50          extends Object implements Serializable {    extends Object implements Serializable
51    {
52  public MarshalledObject(Object obj) {    
53          throw new Error("Not implemented");    //The following fields are from Java API Documentation "Serialized form"
54      private static final long serialVersionUID = 8988374069173025854L;
55      byte[] objBytes;
56      byte[] locBytes;
57      int hash;
58      
59      public MarshalledObject(Object obj) throws java.io.IOException
60      {
61        ByteArrayOutputStream objStream = new ByteArrayOutputStream();
62        RMIMarshalledObjectOutputStream stream = new RMIMarshalledObjectOutputStream(objStream);
63        stream.writeObject(obj);
64        stream.flush();
65        objBytes = objStream.toByteArray();
66        locBytes = stream.getLocBytes();
67        
68        //The following algorithm of calculating hashCode is similar to String
69        hash = 0;
70        for (int i = 0; i < objBytes.length; i++)
71          hash = hash * 31 + objBytes[i];
72        if(locBytes != null)
73          for (int i = 0; i < locBytes.length; i++)
74            hash = hash * 31 + locBytes[i];
75      }
76      
77      public boolean equals(Object obj)
78      {
79        if(obj == null || !(obj instanceof MarshalledObject) )
80          return false;
81        
82        MarshalledObject aobj = (MarshalledObject)obj;
83        if (objBytes == null || aobj.objBytes == null)
84          return objBytes == aobj.objBytes;
85        if (objBytes.length != aobj.objBytes.length)
86          return false;
87        for (int i = 0; i < objBytes.length; i++)
88          {
89            if (objBytes[i] != aobj.objBytes[i])
90              return false;
91          }
92        // Ignore comparison of locBytes(annotation)
93        return true;
94      }
95      
96    public Object get()
97      throws java.io.IOException, java.lang.ClassNotFoundException
98    {
99      if(objBytes == null)
100        return null;
101      RMIMarshalledObjectInputStream stream =
102        new RMIMarshalledObjectInputStream(objBytes, locBytes);
103      return stream.readObject();
104  }  }
105      
106  public boolean equals(Object obj) {    public int hashCode() {
107          throw new Error("Not implemented");      return hash;
108  }    }
109      
 public Object get() {  
         throw new Error("Not implemented");  
 }  
   
 public int hashCode() {  
         throw new Error("Not implemented");  
 }  
   
110  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26