Recent Posts
JavaScript | 17 sec ago
OpenGL Shading | 21 sec ago
PHP | 26 sec ago
None | 48 sec ago
None | 53 sec ago
Haskell | 55 sec ago
None | 1 min ago
None | 1 min ago
None | 2 min ago
Lisp | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 9th of Feb 2010 09:52:19 PM Download | Raw | Embed | Report
  1. package com.pie.jotta.util;
  2.  
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.InputStream;
  5. import java.net.URL;
  6. import java.net.URLConnection;
  7.  
  8. /*
  9.  *  This file is part of Jotta.
  10.  *
  11.  *  Jotta is free software: you can redistribute it and/or modify
  12.  *  it under the terms of the GNU General Public License as published by
  13.  *  the Free Software Foundation, either version 3 of the License, or
  14.  *  (at your option) any later version.
  15.  *
  16.  *  Jotta is distributed in the hope that it will be useful,
  17.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *  GNU General Public License for more details.
  20.  *
  21.  *  You should have received a copy of the GNU General Public License
  22.  *  along with Jotta.  If not, see <http://www.gnu.org/licenses/>.
  23.  */
  24.  
  25. public class CustomClassLoader extends ClassLoader{
  26.        
  27.     public CustomClassLoader(ClassLoader parent) {
  28.         super(parent);
  29.     }
  30.  
  31.     public Class<?> loadClass(String name) throws ClassNotFoundException {
  32.         System.out.println(name);
  33.         if(!name.contains("com.pie.jotta.util.command"))
  34.                 return super.loadClass(name);
  35.  
  36.         try {
  37.                 String[] nameSplit = name.split("[\\.]");
  38.                 name = name.split("[\\.]")[nameSplit.length-1];
  39.                         String url = "file:" + System.getProperty("user.dir")
  40.                                         + "/bin/com/pie/jotta/util/command/"
  41.                                         + (name.endsWith(".class") ? name : name + ".class");
  42.             URL myUrl = new URL(url);
  43.             URLConnection connection = myUrl.openConnection();
  44.             InputStream input = connection.getInputStream();
  45.             ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  46.             int data = input.read();
  47.  
  48.             while(data != -1){
  49.                 buffer.write(data);
  50.                 data = input.read();
  51.             }
  52.  
  53.             input.close();
  54.  
  55.             byte[] classData = buffer.toByteArray();
  56.  
  57.             return defineClass("com.pie.jotta.util.command."+name,
  58.                     classData, 0, classData.length);
  59.  
  60.         } catch (Exception e) {
  61.             System.err.println(e.getMessage());
  62.         }
  63.  
  64.         return null;
  65.     }
  66.  
  67. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: