Changed StartServer to use CRCClassloader. The latter now allows extra jars to be added. Another constructor added to Update.

This commit is contained in:
Travis Burtrum 2010-03-20 02:16:09 -04:00 committed by moparisthebest
parent 63641659e9
commit 70a4c73f10

View File

@ -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<String, byte[]>();
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,6 +131,7 @@ public class CRCClassLoader extends ClassLoader {
// update crc
byte[] classArr = baos.toByteArray();
if (updateCRC)
crc.update(classArr);
String className = entry.getName().substring(0, entry.getName().lastIndexOf(".")).replaceAll("/", ".");
@ -129,6 +141,7 @@ public class CRCClassLoader extends ClassLoader {
}
jf.close();
if (updateCRC)
crcVal = crc.getValue();
}