Imported GNU Classpath 0.90
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. From-SVN: r111942
This commit is contained in:
parent
27079765d0
commit
8aa540d2f7
1367 changed files with 188789 additions and 22762 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue