diff options
author | Egil Moeller <egil.moller@freecode.no> | 2010-03-22 00:16:53 +0100 |
---|---|---|
committer | Egil Moeller <egil.moller@freecode.no> | 2010-03-22 00:16:53 +0100 |
commit | fc00cfedd6c25d1634a1e0d28a7b7bc5f42e1cd7 (patch) | |
tree | 928419d6bfe794865e4b8f0634bd792f795c4b8a /trunk/infrastructure/yuicompressor/src/com/yahoo/platform/yui/compressor/JarClassLoader.java | |
parent | 0fdab3db005c4fa31fb8306b573c0b35073d3e56 (diff) | |
parent | d56b9b3b82cdebcaeb00eec0fcb4326ad21adaa8 (diff) | |
download | etherpad-fc00cfedd6c25d1634a1e0d28a7b7bc5f42e1cd7.tar.gz etherpad-fc00cfedd6c25d1634a1e0d28a7b7bc5f42e1cd7.tar.xz etherpad-fc00cfedd6c25d1634a1e0d28a7b7bc5f42e1cd7.zip |
Merge branch 'master' into plugin-framework
Diffstat (limited to 'trunk/infrastructure/yuicompressor/src/com/yahoo/platform/yui/compressor/JarClassLoader.java')
-rw-r--r-- | trunk/infrastructure/yuicompressor/src/com/yahoo/platform/yui/compressor/JarClassLoader.java | 158 |
1 files changed, 0 insertions, 158 deletions
diff --git a/trunk/infrastructure/yuicompressor/src/com/yahoo/platform/yui/compressor/JarClassLoader.java b/trunk/infrastructure/yuicompressor/src/com/yahoo/platform/yui/compressor/JarClassLoader.java deleted file mode 100644 index a6d3e13..0000000 --- a/trunk/infrastructure/yuicompressor/src/com/yahoo/platform/yui/compressor/JarClassLoader.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * YUI Compressor - * Author: Julien Lecomte <jlecomte@yahoo-inc.com> - * Copyright (c) 2007, Yahoo! Inc. All rights reserved. - * Code licensed under the BSD License: - * http://developer.yahoo.net/yui/license.txt - */ - -package com.yahoo.platform.yui.compressor; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Enumeration; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -public class JarClassLoader extends ClassLoader { - - private static String jarPath; - - public Class loadClass(String name) throws ClassNotFoundException { - - // First check if the class is already loaded - Class c = findLoadedClass(name); - if (c == null) { - c = findClass(name); - } - - if (c == null) { - c = ClassLoader.getSystemClassLoader().loadClass(name); - } - - return c; - } - - private static String getJarPath() { - - if (jarPath != null) { - return jarPath; - } - - String classname = JarClassLoader.class.getName().replace('.', '/') + ".class"; - String classpath = System.getProperty("java.class.path"); - String classpaths[] = classpath.split(System.getProperty("path.separator")); - - for (int i = 0; i < classpaths.length; i++) { - - String path = classpaths[i]; - JarFile jarFile = null; - JarEntry jarEntry = null; - - try { - jarFile = new JarFile(path); - jarEntry = findJarEntry(jarFile, classname); - } catch (IOException ioe) { - /* ignore */ - } finally { - if (jarFile != null) { - try { - jarFile.close(); - } catch (IOException ioe) { - /* ignore */ - } - } - } - - if (jarEntry != null) { - jarPath = path; - break; - } - } - - return jarPath; - } - - private static JarEntry findJarEntry(JarFile jarFile, String entryName) { - - Enumeration entries = jarFile.entries(); - - while (entries.hasMoreElements()) { - JarEntry entry = (JarEntry) entries.nextElement(); - if (entry.getName().equals(entryName)) { - return entry; - } - } - - return null; - } - - protected Class findClass(String name) { - - Class c = null; - String jarPath = getJarPath(); - - if (jarPath != null) { - JarFile jarFile = null; - try { - jarFile = new JarFile(jarPath); - c = loadClassData(jarFile, name); - } catch (IOException ioe) { - /* ignore */ - } finally { - if (jarFile != null) { - try { - jarFile.close(); - } catch (IOException ioe) { - /* ignore */ - } - } - } - } - - return c; - } - - private Class loadClassData(JarFile jarFile, String className) { - - String entryName = className.replace('.', '/') + ".class"; - JarEntry jarEntry = findJarEntry(jarFile, entryName); - if (jarEntry == null) { - return null; - } - - // Create the necessary package if needed... - int index = className.lastIndexOf('.'); - if (index >= 0) { - String packageName = className.substring(0, index); - if (getPackage(packageName) == null) { - definePackage(packageName, "", "", "", "", "", "", null); - } - } - - // Read the Jar File entry and define the class... - Class c = null; - try { - InputStream is = jarFile.getInputStream(jarEntry); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - copy(is, os); - byte[] bytes = os.toByteArray(); - c = defineClass(className, bytes, 0, bytes.length); - } catch (IOException ioe) { - /* ignore */ - } - - return c; - } - - private void copy(InputStream in, OutputStream out) throws IOException { - byte[] buf = new byte[1024]; - while (true) { - int len = in.read(buf); - if (len < 0) break; - out.write(buf, 0, len); - } - } -}
\ No newline at end of file |