/** * Loads and returns the class defined by the specified name and path. * @param name name of the class to load. * @param file file containing the class' bytecode. * @return the class defined by the specified name and path. * @throws IOException if an error occurs. */ private Class<?> loadClass(String name, AbstractFile file) throws IOException { byte[] buffer; // Buffer for the class' bytecode. int offset; // Current offset in buffer. InputStream in; // Stream on the class' bytecode. // Initialisation. buffer = new byte[(int)file.getSize()]; offset = 0; in = null; try { // Loads the content of file in buffer. in = file.getInputStream(); while(offset != buffer.length) offset += in.read(buffer, offset, buffer.length - offset); // Loads the class. return defineClass(name, buffer, 0, buffer.length); } // Frees resources. finally { if(in != null) in.close(); } }