Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 85   Methods: 3
NCLOC: 40   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MarshallUtil.java 0% 0% 0% 0%
coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7   
 8    package org.jboss.cache.marshall;
 9   
 10    import org.jboss.util.stream.MarshalledValueInputStream;
 11    import org.jboss.util.stream.MarshalledValueOutputStream;
 12   
 13    import java.io.ByteArrayInputStream;
 14    import java.io.ByteArrayOutputStream;
 15    import java.io.InputStream;
 16   
 17    /**
 18    * Utility methods related to marshalling and unmarshalling objects.
 19    *
 20    * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
 21    * @version $Revision$
 22    */
 23    public class MarshallUtil
 24    {
 25   
 26    /**
 27    * Creates an object from a byte buffer using
 28    * {@link MarshalledValueInputStream}.
 29    *
 30    * @param bytes serialized form of an object
 31    * @return the object, or <code>null</code> if <code>bytes</code>
 32    * is <code>null</code>
 33    */
 34  0 public static Object objectFromByteBuffer(byte[] bytes) throws Exception
 35    {
 36  0 if (bytes == null)
 37    {
 38  0 return null;
 39    }
 40   
 41  0 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
 42  0 MarshalledValueInputStream input = new MarshalledValueInputStream(bais);
 43  0 Object result = input.readObject();
 44  0 input.close();
 45  0 return result;
 46    }
 47   
 48    /**
 49    * Creates an object from a byte buffer using
 50    * {@link MarshalledValueInputStream}.
 51    *
 52    * @param bytes serialized form of an object
 53    * @return the object, or <code>null</code> if <code>bytes</code>
 54    * is <code>null</code>
 55    */
 56  0 public static Object objectFromByteBuffer(InputStream bytes) throws Exception
 57    {
 58  0 if (bytes == null)
 59    {
 60  0 return null;
 61    }
 62   
 63  0 MarshalledValueInputStream input = new MarshalledValueInputStream(bytes);
 64  0 Object result = input.readObject();
 65  0 input.close();
 66  0 return result;
 67    }
 68   
 69    /**
 70    * Serializes an object into a byte buffer using
 71    * {@link org.jboss.util.stream.MarshalledValueOutputStream}.
 72    *
 73    * @param obj an object that implements Serializable or Externalizable
 74    * @return serialized form of the object
 75    */
 76  0 public static byte[] objectToByteBuffer(Object obj) throws Exception
 77    {
 78  0 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 79  0 MarshalledValueOutputStream out = new MarshalledValueOutputStream(baos);
 80  0 out.writeObject(obj);
 81  0 out.close();
 82  0 return baos.toByteArray();
 83    }
 84   
 85    }