Clover coverage report -
Coverage timestamp: Sat Jul 7 2007 16:41:13 CEST
file stats: LOC: 98   Methods: 4
NCLOC: 51   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JtrRmiClassLoaderServerImpl.java 66.7% 91.7% 100% 88.2%
coverage coverage
 1    /*
 2    * JTRunner is free software; you can redistribute it and/or modify it under the
 3    * terms of the GNU General Public License as published by the Free Software
 4    * Foundation; either version 2, or (at your option) any later version.
 5    */
 6   
 7    package jtr.remote.cl.impl;
 8   
 9    import java.io.BufferedInputStream;
 10    import java.io.IOException;
 11    import java.io.InputStream;
 12    import java.rmi.RemoteException;
 13    import java.rmi.server.UnicastRemoteObject;
 14    import java.util.ArrayList;
 15    import java.util.Collection;
 16    import jtr.remote.cl.*;
 17    import jtr.test.SystemProperties;
 18    import org.apache.log4j.Logger;
 19   
 20    /**
 21    * Default RMI-based implementation of the remote class loader JTR service.
 22    * @author frusso
 23    * @version 4.0
 24    * @since 4.0
 25    */
 26    public class JtrRmiClassLoaderServerImpl extends UnicastRemoteObject implements JtrRmiClassLoaderServer {
 27   
 28    /**
 29    * Creates a new instance of JtrRmiClassLoaderServerImpl
 30    * @throws java.rmi.RemoteException
 31    */
 32  1 public JtrRmiClassLoaderServerImpl() throws RemoteException {
 33  1 super(new Integer(System.getProperty(SystemProperties.TEST_CLASS_LOADER_SERVICE_PORT_PROPERTY,SystemProperties.TEST_CLASS_LOADER_SERVICE_PORT.toString())).intValue());
 34  1 logger.debug("Using "+System.getProperty(SystemProperties.TEST_CLASS_LOADER_SERVICE_PORT_PROPERTY)+"="
 35    +System.getProperty(SystemProperties.TEST_CLASS_LOADER_SERVICE_PORT_PROPERTY,SystemProperties.TEST_CLASS_LOADER_SERVICE_PORT.toString()));
 36    }
 37   
 38    /**
 39    * This method returns a byte array representing the definition of the
 40    * required class whose fully qualified name has been provided as input
 41    * parameter. This method might retunr <code>null</code> just in case
 42    * the required class could not be found.
 43    *
 44    * @param fqn The required class' fqn
 45    * @return The class' definition or <code>null</code>
 46    */
 47  1716 public Byte[] getBytecode(String fqn) throws RemoteException {
 48  1716 return _load( fqn.replace(".","/")+".class" );
 49    }
 50   
 51    /**
 52    * This method returns a byte array whose content represents a generic
 53    * resource loaded from the class-path visible to the current-thread
 54    * running this code.
 55    *
 56    */
 57  39 public Byte[] getResource(String name) throws RemoteException {
 58  39 return _load(name);
 59    }
 60   
 61    /**
 62    * Private method that actually performs the class/resource loading.
 63    */
 64  1756 private Byte[] _load(String name) throws RemoteException {
 65  1756 Byte[] res = null;
 66   
 67  1756 ClassLoader cl = Thread.currentThread().getContextClassLoader();
 68  1756 logger.debug("Loading resource "+name+" using class-loader "+cl);
 69   
 70  1755 InputStream is = cl.getResourceAsStream(name);
 71  1756 if(is!=null) {
 72  1634 BufferedInputStream bis = new BufferedInputStream(is);
 73    // collection for dinamically adding read bytes
 74  1634 Collection<Byte> c = new ArrayList<Byte>();
 75  1634 Integer b = -1;
 76  1634 try {
 77  1634 int buffSize = bis.available();
 78  1634 int readData = -1;
 79  1634 byte[] buff = new byte[buffSize];
 80    // read into the buffer
 81  ? while( (readData=bis.read(buff)) !=-1 ) {
 82    // swap from the buffer into the collection
 83  1634 for(int i=0;i<readData;i++) {
 84  6439602 c.add(buff[i]);
 85    }
 86    }
 87  1634 logger.debug("Done... loaded "+name+" using class-loader "+cl);
 88    } catch (IOException ex) {
 89  0 String msg = "Caught an I/O exception, unable to accomplish the loading of class/resource "+name;
 90  0 throw new RemoteException(msg);
 91    }
 92  1634 res = (Byte[]) c.toArray(new Byte[c.size()]);
 93    }
 94  1756 return res;
 95    }
 96   
 97    private static Logger logger = Logger.getLogger(JtrRmiClassLoader.class);
 98    }