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.jboss;
 
 import  org.jboss.logging.Logger;
 import  org.jboss.serial.objectmetamodel.DataContainer;
 import  org.jboss.serial.objectmetamodel.safecloning.SafeCloningRepository;
 
Does lazy serialization based on JBossSerialization. I'm using JbossSerialization internal's API here, because DataContainer is a repository of final variables, and in case we are only using this MarshalledValue to cross ClassLoader isolations, we don't need to convert the repository to a byteArray.

$Id: LocalMarshalledValue.java 3845 2008-04-02 04:12:05Z ron.sigal@jboss.com $

Author(s):
Clebert Suconic
 
 {
 
    protected static final Logger log = Logger.getLogger(JBossSerializationManager.class);
 
    DataContainer container;
    private static final long serialVersionUID = 6996297171147626666L;
 
    public LocalMarshalledValue()
    {
    }
 
    public LocalMarshalledValue(Object objthrows IOException
    {
        = new DataContainer(false);
       ObjectOutput output = .getOutput();
       output.writeObject(obj);
       output.flush();
       .flush();
    }
 
    public LocalMarshalledValue(Object obj, SafeCloningRepository safeToReusethrows IOException
    {
        = new DataContainer(nullnullsafeToReusefalse);
       ObjectOutput output = .getOutput();
       output.writeObject(obj);
       output.flush();
       .flush();
    }

   
The object has to be unserialized only when the first get is executed.
 
    public Object get() throws IOExceptionClassNotFoundException
    {
       try
       {
          ClassLoader tcl = (ClassLoader) AccessController.doPrivilegednew PrivilegedAction()
          {
             public Object run()
             {
                return Thread.currentThread().getContextClassLoader();
             }
          });
          .getCache().setLoader(tcl);
          return .getInput().readObject();
       }
       catch(RuntimeException e)
      {
         .debug(ee);
         throw e;
      }
   }
   public void writeExternal(ObjectOutput outthrows IOException
   {
	  .warn("LocalmarshalledValue writeExternal is deprecated. This version is best used on call-by-value operations");
      ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
      BufferedOutputStream buffOut = new BufferedOutputStream(byteOut);
      DataOutputStream dataOut = new DataOutputStream(buffOut);
      .saveData(dataOut);
      dataOut.flush();
      byte[] arrayBytes = byteOut.toByteArray();
      out.writeInt(arrayBytes.length);
      out.write(arrayBytes);
      out.flush();
   }
   {
      .warn("LocalmarshalledValue readExternal is deprecated. This version is best used on call-by-value operations");
      byte[] bytes = new byte[in.readInt()];
      in.readFully(bytes);
      ByteArrayInputStream byteInput = new ByteArrayInputStream(bytes);
      DataInputStream input = new DataInputStream(byteInput);
       = new DataContainer(false);
      .loadData(input);
   }
New to GrepCode? Check out our FAQ X