From 70a4c73f10968800b1b01b10609caf9235b52f7b Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Sat, 20 Mar 2010 02:16:09 -0400 Subject: [PATCH] Changed StartServer to use CRCClassloader. The latter now allows extra jars to be added. Another constructor added to Update. --- .../classloader/CRCClassLoader.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/org/moparscape/classloader/CRCClassLoader.java b/src/org/moparscape/classloader/CRCClassLoader.java index ff60096..ef5cf93 100644 --- a/src/org/moparscape/classloader/CRCClassLoader.java +++ b/src/org/moparscape/classloader/CRCClassLoader.java @@ -56,7 +56,6 @@ public class CRCClassLoader extends ClassLoader { * the provided location and tries again. If it fails again, an IOException is thrown. * * @param jarFileLoc The location of the jar file to load on the disk - * */ public CRCClassLoader(String jarFileLoc, String backupURL, long expectedCRC) throws IOException { super(); @@ -94,15 +93,27 @@ public class CRCClassLoader extends ClassLoader { throw new IOException("CRC checksum failed. crc:" + getCRC() + " expected:" + expectedCRC); } + public void addJar(String jarFileLoc) throws IOException { + this.setup(jarFileLoc, false); + } + private void setup(String jarFileLoc) throws IOException { + this.setup(jarFileLoc, true); + } + + private void setup(String jarFileLoc, boolean updateCRC) throws IOException { JarFile jf = new JarFile(jarFileLoc); Enumeration entries = jf.entries(); classes = new HashMap(); - crcVal = 0; - CRC32 crc = new CRC32(); + CRC32 crc = null; + if (updateCRC) { + crcVal = 0; + crc = new CRC32(); + } + byte[] buffer = new byte[1024]; while (entries.hasMoreElements()) { @@ -120,7 +131,8 @@ public class CRCClassLoader extends ClassLoader { // update crc byte[] classArr = baos.toByteArray(); - crc.update(classArr); + if (updateCRC) + crc.update(classArr); String className = entry.getName().substring(0, entry.getName().lastIndexOf(".")).replaceAll("/", "."); // save class @@ -129,7 +141,8 @@ public class CRCClassLoader extends ClassLoader { } jf.close(); - crcVal = crc.getValue(); + if (updateCRC) + crcVal = crc.getValue(); } public long getCRC() { @@ -146,8 +159,8 @@ public class CRCClassLoader extends ClassLoader { public Class findClass(String name) throws ClassNotFoundException { // System.out.println("CRCClassLoader: Requesting class " + name); byte[] classBytes = classes.get(name); - if (classBytes == null){ - if(parent == null) + if (classBytes == null) { + if (parent == null) throw new ClassNotFoundException("Couldn't find class " + name); //System.out.println("Couldn't find class " + name + " trying parent class loader."); return parent.loadClass(name);