Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 
 
 package org.jboss.remoting.serialization.impl.java;
 
A simple replacement for the RMI MarshalledObject that uses the thread context class loader for resolving classes and proxies. This currently does not support class annotations and dynamic class loading.

Author(s):
Scott.Stark@jboss.org
Clebert.suconic@jboss.org (refactored packages and names only)
Version:
$Revision: 566 $
 
       implements java.io.Externalizable
 {
   
Serial Version Identifier.
 
    private static final long serialVersionUID = -1527598981234110311L;

   
The serialized form of the value. If serializedForm is null then the object marshalled was a null reference.
 
    private byte[] serializedForm;

   
The RMI MarshalledObject hash of the serializedForm array
 
    private int hashCode;

   
Exposed for externalization.
 
    public JavaMarshalledValue()
    {
       super();
    }
 
    public JavaMarshalledValue(Object objthrows IOException
    {
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       mvos.writeObject(obj);
       mvos.flush();
        = baos.toByteArray();
       mvos.close();
       // Use the java.rmi.MarshalledObject hash code calculation
       int hash = 0;
       for(int i = 0; i < .i++)
       {
          hash = 31 * hash + [i];
       }
 
        = hash;
    }
 
 
    public Object get() throws IOExceptionClassNotFoundException
    {
       if( == null)
       {
          return null;
       }
 
       MarshalledValueInputStream mvis = new MarshalledValueInputStream(bais);
       Object retValue = mvis.readObject();
      mvis.close();
      return retValue;
   }
   public byte[] toByteArray()
   {
      return ;
   }
   public int size()
   {
      int size =  != null ? . : 0;
      return size;
   }

   
Return a hash code for the serialized form of the value.

Returns:
the serialized form value hash.
   public int hashCode()
   {
      return ;
   }
   public boolean equals(Object obj)
   {
      if(this == obj)
      {
         return true;
      }
      boolean equals = false;
      if(obj instanceof JavaMarshalledValue)
      {
         JavaMarshalledValue mv = (JavaMarshalledValueobj;
         if( == mv.serializedForm)
         {
            equals = true;
         }
         else
         {
            equals = Arrays.equals(mv.serializedForm);
         }
      }
      return equals;
   }

   
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Parameters:
in the stream to read data from in order to restore the object
Throws:
java.io.IOException if I/O errors occur
java.lang.ClassNotFoundException If the class for an object being restored cannot be found.
   {
      int length = in.readInt();
       = null;
      if(length > 0)
      {
          = new byte[length];
         in.readFully();
      }
       = in.readInt();
   }

   
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Parameters:
out the stream to write the object to
Throws:
java.io.IOException Includes any I/O exceptions that may occur
SerialData:
Overriding methods should use this tag to describe the data layout of this Externalizable object. List the sequence of element types and, if possible, relate the element to a public/protected field and/or method of this Externalizable class.
   public void writeExternal(ObjectOutput outthrows IOException
   {
      int length =  != null ? . : 0;
      out.writeInt(length);
      if(length > 0)
      {
         out.write();
      }
      out.writeInt();
   }
New to GrepCode? Check out our FAQ X